messagingfw/senduiservices/src/SendUiImpl.cpp
changeset 15 ff168ad79dda
parent 3 28ae839b4c09
child 17 d6ba66e59a81
equal deleted inserted replaced
3:28ae839b4c09 15:ff168ad79dda
     1 /*
       
     2 * Copyright (c) 2002-2006 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:   Can be used to show "Send" list query and to create and send
       
    15 *                messages via available sending services. Created messages are
       
    16 *                sent directly or message editor is opened for editing,
       
    17 *                depending on the type of the selected service.
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 #include <coemain.h>
       
    23 #include <Sendnorm.rsg>
       
    24 #include <aknlistquerydialog.h>
       
    25 #include <eikmenup.h>
       
    26 #include <data_caging_path_literals.hrh>
       
    27 #include <DRMHelper.h>
       
    28 #include <centralrepository.h>
       
    29 #include <e32cmn.h> // Uid
       
    30 #include <e32property.h>
       
    31 #include <barsread.h>
       
    32 #include <akninputblock.h>
       
    33 #include <centralrepository.h>
       
    34 #include <miutset.h>
       
    35 #include <MessagingDomainCRKeys.h>
       
    36 #include <mtclreg.h>
       
    37 #include <mtudreg.h>
       
    38 
       
    39 // Features
       
    40 #include <featmgr.h>    
       
    41 #include <bldvariant.hrh>
       
    42 #include <MsgMimeTypes.h>
       
    43 #include <CSendingServiceInfo.h>
       
    44 #include <CSendingService.h>
       
    45 #include <CMessageData.h>
       
    46 #include <SendUiConsts.h>
       
    47 #include <senduisingleton.h>
       
    48 
       
    49 #include "SendUiImpl.h"
       
    50 #include "senduiserviceclient.h"
       
    51 #include "SendUiCapabilityCheck.h"
       
    52 #include "SendUiUtils.h"
       
    53 #include "senduiserviceslog.h"              // Logging
       
    54 #include "SendUiPrivateCRKeys.h"
       
    55 #include "senduiproperty.h"
       
    56 #include "propertyobserver.h"
       
    57 #include "senduilauncher.h"
       
    58 #include "SendUiInternalConsts.h"
       
    59 
       
    60 
       
    61 const TInt KArrayGranularity = 2;
       
    62 const TInt KSendUiServiceOrderArrayGranularity = 6;
       
    63 const TInt KTitleBufLength = 64;
       
    64 //Mail Tech Uid
       
    65 const TUid KMailTechnologyTypeUid = { 0x10001671 };
       
    66 //CMail Tech Uid
       
    67 #define KUidMsgTypeFsMtmVal     0x2001F406
       
    68 
       
    69 
       
    70 _LIT( KSendUiResourceFileName,"sendnorm.rsc" );
       
    71 
       
    72 // ======== MEMBER FUNCTIONS ========
       
    73 // -----------------------------------------------------------------------------
       
    74 // CSendUiImpl::NewL
       
    75 // Two-phased constructor.
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CSendUiImpl* CSendUiImpl::NewL()
       
    79     {
       
    80     CSendUiImpl* self = new( ELeave ) CSendUiImpl;
       
    81     
       
    82     CleanupStack::PushL( self );
       
    83     self->ConstructL();
       
    84     CleanupStack::Pop( self );
       
    85 
       
    86     return self;
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // Destructor
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 CSendUiImpl::~CSendUiImpl()
       
    94     {
       
    95     iResourceLoader.Close();
       
    96     TInt count = iSendingServices.Count();
       
    97     while ( count )
       
    98         {
       
    99         delete iSendingServices[--count];
       
   100         }
       
   101     iSendingServices.Close();
       
   102     delete iSendUiServicesOrderArray;
       
   103     delete iServicesToDim;
       
   104     delete iPropertyObserver;
       
   105     delete iSingleton;
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // AddTypedMenuItemL
       
   110 //
       
   111 // No menu item is added, if services are not found. This can happen if asyncronous
       
   112 // sending service update is not yet finished.
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 void CSendUiImpl::AddTypedMenuItemL(
       
   116     CSendUi::TSendUiMenuType    aMenuType,
       
   117     CEikMenuPane&               aMenuPane,
       
   118     TInt                        aIndex,
       
   119     TInt                        aCommandId,
       
   120     TSendingCapabilities        aRequiredCapabilities )
       
   121     {
       
   122     TInt i(0);
       
   123     TBool menuItemAdded = EFalse;
       
   124     TBuf<KTitleBufLength> menuItemName;
       
   125     
       
   126      // Read the resources
       
   127     aMenuType == CSendUi::ESendMenu ? 
       
   128         i = R_SENDUI_MENUITEM_SEND : 
       
   129         i = R_SENDUI_MENUITEM_WRITE; // CSendUi::EWriteMenu
       
   130         
       
   131     iCoeEnv->ReadResourceL( menuItemName, i );
       
   132   
       
   133     for ( i = 0; i < iSendingServices.Count(); i++ )
       
   134     {
       
   135     TUid serviceUid = iSendingServices[i]->ServiceId();
       
   136     if ( QueryCapabilities( i, aRequiredCapabilities ) )
       
   137         {
       
   138         CEikMenuPaneItem::SData data;
       
   139         data.iCascadeId = NULL;
       
   140         data.iText = menuItemName;
       
   141         data.iCommandId = aCommandId;
       
   142         data.iFlags = 0;
       
   143 
       
   144         if ( aIndex == aMenuPane.NumberOfItemsInPane() )
       
   145             {
       
   146             aMenuPane.AddMenuItemL( data );
       
   147             }
       
   148         else
       
   149             {
       
   150             aMenuPane.InsertMenuItemL( data, aIndex );
       
   151             }
       
   152             
       
   153         menuItemAdded = ETrue;
       
   154         break;
       
   155         }
       
   156     }
       
   157 
       
   158     // Hide menu item if sending is already in progress.
       
   159     if ( menuItemAdded )
       
   160         {
       
   161         aMenuPane.SetItemDimmed( aCommandId, iIsSending);
       
   162         }        
       
   163     }
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // ShowTypedQueryAndSendL
       
   167 // First shows list query and then creates the message.
       
   168 // Editor is launched for editing the message or the message is sent
       
   169 // directly without opening the editor. Functionality depends on the
       
   170 // type of selected sending service.
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 void CSendUiImpl::ShowTypedQueryAndSendL(
       
   174     CSendUi::TSendUiMenuType    aMenuType,
       
   175     const CMessageData*         aMessageData,
       
   176     TSendingCapabilities        aRequiredCapabilities,
       
   177     CArrayFix<TUid>*            aServicesToDim,
       
   178     TBool                       aLaunchEditorEmbedded,
       
   179     const TDesC&                aTitleText )
       
   180     {
       
   181     TUid serviceId = ShowTypedQueryL(
       
   182         aMenuType,
       
   183         aMessageData,
       
   184         aRequiredCapabilities,
       
   185         aServicesToDim,
       
   186         aTitleText );
       
   187 
       
   188     if ( serviceId != KNullUid )
       
   189         {
       
   190         // Process user selection.
       
   191         CreateAndSendMessageL(
       
   192             serviceId,
       
   193             aMessageData,
       
   194             aLaunchEditorEmbedded);
       
   195         }
       
   196     }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // ShowTypedQueryL
       
   200 // Shows list query and returns the user selection.
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 TUid CSendUiImpl::ShowTypedQueryL(
       
   204     CSendUi::TSendUiMenuType    aMenuType,
       
   205     const CMessageData*         aMessageData,
       
   206     TSendingCapabilities        aRequiredCapabilities,
       
   207     CArrayFix<TUid>*            aServicesToDim,
       
   208     const TDesC&                aTitleText )
       
   209     {
       
   210     // Implemented for CR # 401-1806 >>    
       
   211     // This section to enable/disable features (supported by feature manager) at run time, is to be revised,
       
   212     // once an observer class is available from feature manager side to intimate about feature state
       
   213 		
       
   214     CRepository* repository = CRepository::NewLC( KCRUidSendUi );
       
   215     TInt oldFeatures(0);   
       
   216     TInt newFeatures(0); 
       
   217     TBool updateNeeded( EFalse );   
       
   218     
       
   219     if ( repository->Get( KKeySendUiFeatureManagerServices, oldFeatures ) != KErrNone )
       
   220     	{
       
   221     	updateNeeded = ETrue;
       
   222     	}
       
   223     FeatureManager::InitializeLibL();
       
   224     FeatureStatus( KFeatureIdMmsPostcard, newFeatures, KSendUiPostcard );
       
   225     FeatureStatus( KFeatureIdAudioMessaging, newFeatures, KSendUiAudioMessage );
       
   226     FeatureStatus( KFeatureIdSenduiMmsUpload, newFeatures, KSendUiMmsUpload );
       
   227     FeatureManager::UnInitializeLib();
       
   228     if ( newFeatures != oldFeatures )
       
   229         {
       
   230         repository->Set( KKeySendUiFeatureManagerServices, newFeatures );
       
   231         updateNeeded = ETrue;
       
   232         }
       
   233 
       
   234     CleanupStack::PopAndDestroy( repository );
       
   235     
       
   236     RProperty propertyUpdateOperation;
       
   237     TRequestStatus status;
       
   238     if ( updateNeeded )
       
   239         {
       
   240         RProperty::Set( 
       
   241             KPSUidSendUiProperty, 
       
   242             KSendUiUpdateRequest, 
       
   243             KSendUiUpdateRequested );
       
   244         User::LeaveIfError( propertyUpdateOperation.Attach( KPSUidSendUiProperty, KSendUiUpdateRequest ));
       
   245         propertyUpdateOperation.Subscribe( status );	
       
   246         User::WaitForRequest(status);
       
   247         TInt value = KErrNone;
       
   248         if(propertyUpdateOperation.Get( value ) !=KErrNotFound && value == KSendUiUpdated )
       
   249             {
       
   250             TRAPD( err, GetServicesL() );
       
   251             if ( err )
       
   252                 {
       
   253 #ifdef _DEBUG
       
   254                 TBuf<256> buf;
       
   255                 buf.Format(_L("SendUi err"));
       
   256                 User::InfoPrint(buf);
       
   257 #endif
       
   258                 TUid serviceId( KNullUid );
       
   259                 return serviceId;
       
   260                 }
       
   261             }
       
   262         propertyUpdateOperation.Close();
       
   263         }
       
   264     // Implemented for CR # 401-1806 <<    
       
   265     // List items for list query.
       
   266     CDesCArrayFlat* listItems = new (ELeave) CDesCArrayFlat( KArrayGranularity );
       
   267     CleanupStack::PushL( listItems);
       
   268 
       
   269     // This array is used to map user selection to correct service.
       
   270     CArrayFix<TUid>* listItemUids = 
       
   271         new ( ELeave ) CArrayFixFlat<TUid>( KArrayGranularity );
       
   272     CleanupStack::PushL( listItemUids );
       
   273 
       
   274     iServicesToDim->Reset();
       
   275 
       
   276     TInt i = 0;
       
   277     if ( aServicesToDim )
       
   278         {
       
   279         for ( i = 0; i < aServicesToDim->Count(); i++  )
       
   280             {
       
   281             iServicesToDim->AppendL( (*aServicesToDim)[i] );
       
   282             }
       
   283         }
       
   284   
       
   285     // Get and filter ECom based services.
       
   286     FilterServicesL(
       
   287         *listItems,
       
   288         *listItemUids,
       
   289         aRequiredCapabilities,
       
   290         aMessageData,
       
   291         aMenuType );
       
   292 
       
   293     TUid serviceId( KNullUid );
       
   294     if ( listItems->Count() > 0 )
       
   295         {
       
   296         // Show list query.
       
   297         SortListL( *listItems, *listItemUids );
       
   298 
       
   299         serviceId = ShowListQueryL(
       
   300             listItems,
       
   301             *listItemUids,
       
   302             aTitleText,
       
   303             aMenuType );
       
   304         }
       
   305 
       
   306     CleanupStack::PopAndDestroy( 2, listItems );  // listItemUids, listItems
       
   307 
       
   308     return serviceId;
       
   309     }
       
   310 
       
   311 // -----------------------------------------------------------------------------
       
   312 // SendMessageL
       
   313 // -----------------------------------------------------------------------------
       
   314 TInt CSendUiImpl::SendMessageL(    
       
   315     TUid                    aServiceUid,
       
   316     const CMessageData*     aMessageData,
       
   317     TBool                   aLaunchEditorEmbedded)
       
   318     { 
       
   319     if ( iIsSending || aServiceUid == KNullUid )
       
   320         {
       
   321         return KErrNone;
       
   322         }
       
   323         
       
   324         CAknInputBlock* absorber = CAknInputBlock::NewLC( ); 
       
   325         // Ensures proper sending state if leave happens.
       
   326         iIsSending = ETrue;
       
   327         TInt success( KErrNone );
       
   328         CleanupStack::PushL( TCleanupItem( ResetIsSending, (TAny*)&iIsSending ) );
       
   329 
       
   330         // Create the requested ECom service.
       
   331         TInt i( ResolveServiceIndex( aServiceUid ));
       
   332         if ( i != KErrNotFound )
       
   333             {
       
   334             TRAP( success, 
       
   335                 CSendingService* sendingService = CSendingService::NewL( 
       
   336                     iSendingServices[i]->ServiceProviderId(), *iCoeEnv, *iSingleton );
       
   337                 CleanupStack::PushL( sendingService );  
       
   338                 
       
   339                 sendingService->CreateAndSendMessageL( aServiceUid, aMessageData, aLaunchEditorEmbedded );
       
   340                 CleanupStack::PopAndDestroy( sendingService );
       
   341                     );
       
   342                 
       
   343             }
       
   344         else
       
   345             {
       
   346             iIsSending = EFalse;
       
   347             }
       
   348     CleanupStack::PopAndDestroy( 2, absorber); // TCleanupItem, absorber
       
   349     return success;
       
   350     }
       
   351 
       
   352 // -----------------------------------------------------------------------------
       
   353 // SendMessageViaServer
       
   354 // -----------------------------------------------------------------------------
       
   355 //
       
   356 void CSendUiImpl::SendMessageViaServerL( 
       
   357     TUid                    aServiceUid,
       
   358     const CMessageData*     aMessageData,
       
   359     TBool                   aLaunchEditorEmbedded )
       
   360     {
       
   361     TInt index( ResolveServiceIndex( aServiceUid ));
       
   362     TBool capabilitiesOk = ETrue;
       
   363     if ( index == KErrNotFound )
       
   364     	{
       
   365     	return;
       
   366     	}
       
   367     if ( iSendingServices[index]->ServiceFeatures() & CSendingServiceInfo::EServiceCanSendDirectly )
       
   368     	{
       
   369 	    // Check sending rights
       
   370 	    RProcess process;
       
   371 	    TSecurityInfo securityInfo( process );
       
   372 	    CSendUiCapabilityCheck* capabilityCheck = CSendUiCapabilityCheck::NewLC();
       
   373 
       
   374 		capabilitiesOk = capabilityCheck->CheckCapabilitiesL( 
       
   375 		    securityInfo, 
       
   376 		    iSingleton->MsvSessionL(), 
       
   377 		    KSenduiMtmMmsUid, 
       
   378 		    iSendingServices[index]->ServiceName() );
       
   379 		    
       
   380 		CleanupStack::PopAndDestroy( capabilityCheck );
       
   381 	    }
       
   382     
       
   383     if ( capabilitiesOk )
       
   384     	{
       
   385         TUid providerUid = iSendingServices[index]->ServiceProviderId();	
       
   386 	    RSendUiServiceClient sendUiClient;
       
   387 	    CleanupClosePushL( sendUiClient );
       
   388 	    sendUiClient.ConnectChainedAppL( KSendUiLauncherAppUid );
       
   389 	    // LaunchSendUiL is syncronous operation
       
   390 	    sendUiClient.LaunchSendUiL( 
       
   391 	        aServiceUid,
       
   392 	        providerUid,
       
   393 	        aLaunchEditorEmbedded, 
       
   394 	        aMessageData ); 
       
   395 	    CleanupStack::PopAndDestroy( &sendUiClient);
       
   396     	}
       
   397 	    
       
   398     }
       
   399 
       
   400 // -----------------------------------------------------------------------------
       
   401 // CreateAndSendMessageL
       
   402 // Creates the message and launches the editor for editing the message
       
   403 // or sends the message directly without opening the editor. 
       
   404 // Functionality depends on the type of selected sending service.
       
   405 // -----------------------------------------------------------------------------
       
   406 //
       
   407 void CSendUiImpl::CreateAndSendMessageL(
       
   408     TUid                    aServiceUid,
       
   409     const CMessageData*     aMessageData,
       
   410     TBool                   aLaunchEditorEmbedded )
       
   411     {
       
   412     LOGTEXT(_L("CSendUiImpl::CreateAndSendMessageL >>"));
       
   413     TInt err(0); // initializing this to 0 helps debugging SendMessageViaServerL
       
   414     err = SendMessageL( aServiceUid, aMessageData, aLaunchEditorEmbedded );
       
   415     if ( !iServerAppLaunch && ( err == KErrPermissionDenied || err == KErrAccessDenied ) )
       
   416         {
       
   417         SendMessageViaServerL( aServiceUid, aMessageData, aLaunchEditorEmbedded );
       
   418         }
       
   419     else
       
   420        	{
       
   421         User::LeaveIfError( err );
       
   422        	}
       
   423     LOGTEXT(_L("CSendUiImpl::CreateAndSendMessageL <<"));
       
   424    }
       
   425 
       
   426 // -----------------------------------------------------------------------------
       
   427 // ServiceCapabilitiesL
       
   428 // Returns sending capabilities of the sending service.
       
   429 // -----------------------------------------------------------------------------
       
   430 //
       
   431 TInt CSendUiImpl::ServiceCapabilities(
       
   432     TUid                    aServiceUid,
       
   433     TSendingCapabilities&   aServiceCapabilities )
       
   434     {
       
   435     TInt i( ResolveServiceIndex( aServiceUid ));
       
   436     
       
   437     if ( i != KErrNotFound )
       
   438         {
       
   439         aServiceCapabilities = 
       
   440             iSendingServices[i]->ServiceCapabilities();
       
   441         i = KErrNone;        
       
   442         }
       
   443     return i;
       
   444     }
       
   445 
       
   446 // -----------------------------------------------------------------------------
       
   447 // AvailableServicesL
       
   448 // Populates given list with the information about services
       
   449 // provided by specified ECom service provider.
       
   450 // (other items were commented in a header).
       
   451 // -----------------------------------------------------------------------------
       
   452 //
       
   453 
       
   454 void CSendUiImpl::AvailableServicesL(
       
   455     RPointerArray<CSendingServiceInfo>& aServiceList,
       
   456     TUid aServiceProvider)
       
   457     {
       
   458     for ( TInt i(0); i < iSendingServices.Count(); i++ )
       
   459         {
       
   460         if ( iSendingServices[i]->ServiceProviderId() == aServiceProvider 
       
   461             || aServiceProvider == KNullUid )
       
   462             {
       
   463             CSendingServiceInfo* serviceInfo = iSendingServices[i]->CopyLC();
       
   464             aServiceList.AppendL( serviceInfo );
       
   465             CleanupStack::Pop( serviceInfo ); // serviceInfo
       
   466             }
       
   467         }
       
   468     }
       
   469 // -----------------------------------------------------------------------------
       
   470 // TechnologyType
       
   471 // -----------------------------------------------------------------------------
       
   472 //
       
   473 TUid CSendUiImpl::TechnologyType( TUid aServiceUid )
       
   474     {
       
   475     TInt i = ResolveServiceIndex( aServiceUid );
       
   476     if ( i != KErrNotFound )
       
   477         {
       
   478         return iSendingServices[i]->TechnologyTypeId(); 
       
   479         }
       
   480     else
       
   481         {        
       
   482         return TUid::Null();
       
   483         }
       
   484     }
       
   485 
       
   486 // -----------------------------------------------------------------------------
       
   487 //
       
   488 // -----------------------------------------------------------------------------
       
   489 //
       
   490 TInt CSendUiImpl::ResolveServiceIndex( TUid aServiceUid )
       
   491     {
       
   492     TInt index( iSendingServices.Count() );
       
   493     
       
   494     while( --index >= 0)
       
   495         {
       
   496         if ( iSendingServices[index]->ServiceId() == aServiceUid )
       
   497             {
       
   498             return index;           
       
   499             }
       
   500         }
       
   501     return KErrNotFound;
       
   502     }
       
   503 
       
   504 // -----------------------------------------------------------------------------
       
   505 // QueryCapabilities
       
   506 // -----------------------------------------------------------------------------
       
   507 //
       
   508 TBool CSendUiImpl::QueryCapabilities( 
       
   509     TInt index, 
       
   510     TSendingCapabilities aRequiredCapabilities )
       
   511     {
       
   512     if ( index == KErrNotFound )
       
   513     	{
       
   514     	return EFalse;
       
   515     	}
       
   516 
       
   517      if ( aRequiredCapabilities.iFlags == TSendingCapabilities::EAllServices )
       
   518         { 
       
   519         // No capabilities required from service
       
   520         return ETrue;
       
   521         }
       
   522     TSendingCapabilities serviceCap = iSendingServices[ index ]->ServiceCapabilities();
       
   523     
       
   524     if ( !(serviceCap.iMessageSize == 0 // no size limit set for the service
       
   525     || aRequiredCapabilities.iMessageSize == 0 ) // no size limit asked from the client
       
   526     && aRequiredCapabilities.iMessageSize > serviceCap.iMessageSize )
       
   527         {
       
   528         return EFalse;
       
   529         }
       
   530     
       
   531     // Check if support for attachments are required.
       
   532     if ( aRequiredCapabilities.iFlags & TSendingCapabilities::ESupportsAttachments
       
   533         && serviceCap.iFlags & TSendingCapabilities::ESupportsAttachments )
       
   534         {
       
   535         return ETrue;
       
   536         }
       
   537 
       
   538     // Check if support for body text is required.
       
   539     if ( aRequiredCapabilities.iFlags & TSendingCapabilities::ESupportsBodyText )
       
   540         {
       
   541         if ( serviceCap.iFlags & TSendingCapabilities::ESupportsBodyText )
       
   542             {
       
   543             if ( serviceCap.iBodySize > 0 && aRequiredCapabilities.iBodySize > serviceCap.iBodySize )
       
   544                 {
       
   545                 return EFalse; // size limit defined and it is enough
       
   546                 }
       
   547             // no size limit in service for bodytext or required size below max size.
       
   548             return ETrue;
       
   549             }
       
   550         }
       
   551         
       
   552     
       
   553     // Check if support for BIO sending is required.
       
   554         if ( aRequiredCapabilities.iFlags & TSendingCapabilities::ESupportsBioSending 
       
   555              && serviceCap.iFlags & TSendingCapabilities::ESupportsBioSending )
       
   556             {
       
   557             return ETrue;
       
   558             }
       
   559 
       
   560     // Check if support for editor is required.
       
   561         if ( aRequiredCapabilities.iFlags & TSendingCapabilities::ESupportsEditor
       
   562              && serviceCap.iFlags & TSendingCapabilities::ESupportsEditor )
       
   563             {
       
   564             return ETrue;
       
   565             }
       
   566     return EFalse;
       
   567     }
       
   568 
       
   569 // -----------------------------------------------------------------------------
       
   570 // CSendUiImpl::GetServicesL
       
   571 // 
       
   572 // (other items were commented in a header).
       
   573 // -----------------------------------------------------------------------------
       
   574 //
       
   575 
       
   576 void CSendUiImpl::GetServicesL( )
       
   577 {
       
   578     TInt value(0);
       
   579     TInt serviceCount;
       
   580     TInt cleanupItems(0);
       
   581     
       
   582     CRepository* rep = CRepository::NewLC( KCRUidSendUi );
       
   583     cleanupItems++;
       
   584     TInt err = rep->Get( KKeySendUiServiceCount, serviceCount );
       
   585     
       
   586     if ( err )
       
   587         {
       
   588         LOGTEXT(_L("SendUiImpl->GetServicesL: Cenrep init file missing"));
       
   589         CleanupStack::PopAndDestroy( rep );
       
   590         return;
       
   591         }
       
   592     else
       
   593         {
       
   594         if ( serviceCount == KSendUiNotInitialized )
       
   595             {
       
   596             // Services has not been initialized, launch service resolver in the bacground.
       
   597             CleanupStack::PopAndDestroy( rep);
       
   598             // iSendingServices are updated, when update is done.
       
   599             RProperty::Set( 
       
   600                 KPSUidSendUiProperty, 
       
   601                 KSendUiUpdateRequest, 
       
   602                 KSendUiUpdateRequested); 
       
   603 
       
   604             return;            
       
   605             }
       
   606         }
       
   607     
       
   608     while ( iSendingServices.Count() )
       
   609         {
       
   610         delete iSendingServices[0];
       
   611         iSendingServices.Remove(0);
       
   612         }
       
   613         
       
   614     HBufC* text = HBufC::NewLC( KSendUiServiceMaxNameLength );
       
   615     cleanupItems++;
       
   616     TPtr ptr = text->Des();
       
   617     TInt key;
       
   618     for( TInt i(0); i < serviceCount; i++ )
       
   619         {
       
   620         key = KSendUiServiceIndex * i;
       
   621         CSendingServiceInfo* info = CSendingServiceInfo::NewLC();
       
   622     
       
   623         err = rep->Get( key | KSendUiServiceId, value );
       
   624         if (!err )
       
   625             {
       
   626             info->SetServiceId( TUid::Uid( value  ));
       
   627             }
       
   628 
       
   629         err = rep->Get( key | KSendUiServiceProviderId, value );
       
   630         if (!err )
       
   631             {
       
   632             info->SetServiceProviderId( TUid::Uid( value  ));
       
   633             }
       
   634 
       
   635        err = rep->Get( key | KSendUiServiceName, ptr );
       
   636         if (!err)
       
   637             {
       
   638             __ASSERT_DEBUG( ptr.Length() <= KSendUiServiceMaxNameLength, User::Invariant() );
       
   639             info->SetServiceNameL( ptr );
       
   640             }
       
   641         
       
   642         err = rep->Get( key | KSendUiServiceMenuName, ptr );
       
   643         if (!err)
       
   644             {
       
   645             __ASSERT_DEBUG( ptr.Length() <= KSendUiServiceMaxNameLength, User::Invariant() );
       
   646             info->SetServiceMenuNameL( ptr );
       
   647             }
       
   648         
       
   649         err = rep->Get( key | KSendUiServiceAddress, ptr );
       
   650         if (!err)
       
   651             {
       
   652             __ASSERT_DEBUG( ptr.Length() <= KSendUiServiceMaxNameLength, User::Invariant() );
       
   653             info->SetServiceAddressL( ptr );
       
   654             }
       
   655         
       
   656         TSendingCapabilities cap;
       
   657             
       
   658         err = rep->Get( key | KSendUiServiceFlags, value );
       
   659         if (!err)
       
   660             {
       
   661             cap.iFlags = value;
       
   662             }
       
   663         
       
   664         err = rep->Get( key | KSendUiServiceBodySize, value );
       
   665         if (!err)
       
   666             {
       
   667             cap.iBodySize = value;
       
   668             }
       
   669         
       
   670         err = rep->Get( key | KSendUiServiceMessageSize, value );
       
   671         if (!err)
       
   672             {
       
   673             cap.iMessageSize = value;
       
   674             }
       
   675     
       
   676     
       
   677         err = rep->Get( key | KSendUiServiceTechnologyType, value );
       
   678         if (!err )
       
   679             {
       
   680             info->SetTechnologyTypeId( TUid::Uid( value  ));
       
   681             }
       
   682         
       
   683         err = rep->Get( key | KSendUiServiceFeatures, value );
       
   684         if (!err)
       
   685             {
       
   686             info->SetServiceFeatures( value );
       
   687             }
       
   688     
       
   689         if (!err)
       
   690             {
       
   691             info->SetServiceCapabilities( cap );            
       
   692             iSendingServices.Append( info );
       
   693             CleanupStack::Pop( info);
       
   694             }
       
   695 
       
   696         }
       
   697     
       
   698     CleanupStack::PopAndDestroy( cleanupItems, rep); // text, rep
       
   699     
       
   700 }
       
   701 
       
   702 // ---------------------------------------------------------
       
   703 // ShowListQueryL(
       
   704 // Displays list query.
       
   705 // (other items were commented in a header).
       
   706 // ---------------------------------------------------------
       
   707 // 
       
   708 TUid CSendUiImpl::ShowListQueryL(
       
   709     MDesCArray*                 aListItems,
       
   710     const CArrayFix<TUid>&      aListItemUids,
       
   711     const TDesC&                aTitleText,
       
   712     CSendUi::TSendUiMenuType    aMenuType )
       
   713     {
       
   714     // Show list query.
       
   715     TInt choice = KErrNotFound;
       
   716     CAknListQueryDialog* dlg = new (ELeave) CAknListQueryDialog( &choice );
       
   717     TInt ret = 0;
       
   718     TRAPD( err, 
       
   719     dlg->PrepareLC( R_SENDUI_LIST_QUERY );
       
   720     dlg->SetItemTextArray( aListItems );
       
   721     dlg->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   722 
       
   723     // Set title
       
   724     CAknPopupHeadingPane* heading = dlg->Heading();
       
   725 
       
   726     if ( aTitleText != KNullDesC )
       
   727         {
       
   728         heading->SetTextL( aTitleText );
       
   729         }
       
   730     else 
       
   731         {
       
   732         HBufC* title;
       
   733         TInt titleId(0);
       
   734         if (aMenuType == CSendUi::ESendMenu )
       
   735             {
       
   736             titleId = R_SENDUI_LIST_QUERY_TITLE ;
       
   737             }
       
   738         else if ( aMenuType == CSendUi::EWriteMenu )
       
   739             {
       
   740             titleId = R_SENDUI_LIST_QUERY_TITLE_WRITE;
       
   741             }
       
   742         
       
   743         if ( titleId )
       
   744             {
       
   745             title = iCoeEnv->AllocReadResourceLC( titleId );
       
   746             heading->SetTextL( *title );
       
   747             CleanupStack::PopAndDestroy( title );
       
   748             }
       
   749         }
       
   750     
       
   751     ret = dlg->RunLD();
       
   752     ); //end of TRAPD
       
   753     
       
   754     if( err == KLeaveExit )
       
   755         {
       
   756         delete dlg;
       
   757         dlg = NULL;
       
   758         }
       
   759     
       
   760     if ( !ret )
       
   761         {
       
   762         return KNullUid;
       
   763         }
       
   764     return aListItemUids.At( choice );
       
   765     }
       
   766 
       
   767 
       
   768 // -----------------------------------------------------------------------------
       
   769 // CanSendContentL
       
   770 // -----------------------------------------------------------------------------
       
   771 //
       
   772 TBool CSendUiImpl::CanSendContentL(
       
   773     TUid                    aServiceUid,
       
   774     TUid                    aServiceProviderId,
       
   775     const CMessageData*     aMessageData,
       
   776     TDataType*              aMimeType )
       
   777     {
       
   778     // Other ecoms are filtered by their base provider, but versitile MTMs under 
       
   779     // GenericMtmPlugin have filtering by their serviceUid    
       
   780     if ( aServiceProviderId != KGenericMtmPlugin )
       
   781     {
       
   782         aServiceUid = aServiceProviderId;
       
   783     }
       
   784     // Content based filtering is done only for some selected services.
       
   785     // Cannot filter with no data, certain services and audio message (if no audiomessage support)
       
   786     if ( !aMessageData ||
       
   787          !( aServiceUid == KDrmLinkSender || 
       
   788             aServiceUid == KSenduiMtmPostcardUid ||
       
   789             aServiceUid == KMmsDirectUpload ||
       
   790             aServiceUid == KMmsIndirectUpload ||
       
   791             aServiceUid == KSenduiMtmAudioMessageUid ||
       
   792             aServiceUid == KSenduiMtmSmsUid ) )                            
       
   793         {
       
   794         return ETrue;
       
   795         }
       
   796 
       
   797 
       
   798     const CDesCArray& attachmentPaths = aMessageData->AttachmentArray();
       
   799     const RArray<RFile>& attachments = aMessageData->AttachmentHandleArray();
       
   800 
       
   801     TInt attachmentCount = attachmentPaths.Count() + attachments.Count();
       
   802 
       
   803     if ( attachmentCount == 0 )
       
   804         { // No content to send
       
   805         
       
   806         if ( aServiceUid == KDrmLinkSender )
       
   807             {
       
   808             return EFalse;
       
   809             }
       
   810         TInt bodyTextLength = aMessageData->BodyText()->DocumentLength();
       
   811         // Dim MMS Upload services, if there is no bodytext
       
   812         if ( ( aServiceUid == KMmsDirectUpload 
       
   813             || aServiceUid == KMmsIndirectUpload ) 
       
   814             && bodyTextLength == 0 )
       
   815             {
       
   816             return EFalse; // bodytext will be converted into attachment
       
   817             }
       
   818         // Dim Audio message, if there is bodytext    
       
   819         if ( aServiceUid == KSenduiMtmAudioMessageUid 
       
   820             && bodyTextLength > 0 )
       
   821             {
       
   822             return EFalse;
       
   823             }
       
   824         return ETrue;
       
   825         }
       
   826     else if ( attachmentCount == 1  )
       
   827         {
       
   828         TBool result = ETrue;
       
   829         
       
   830         switch ( aServiceUid.iUid )
       
   831             {
       
   832             case KSenduiMtmSmsUidValue: 
       
   833                 {
       
   834                 if ( aMimeType->Des8().CompareF( KMsgMimeVCard ) != 0 &&
       
   835                      aMimeType->Des8().CompareF( KMsgMimeVCal ) != 0 )
       
   836                     {
       
   837                     result = EFalse;
       
   838                     }
       
   839                 break;
       
   840                 }
       
   841             case KSenduiMtmPostcardUidValue:
       
   842                 {
       
   843                 if( aMimeType->Des8().CompareF( KMsgMimeImageJpeg ) != 0 &&
       
   844                     aMimeType->Des8().CompareF( KMsgMimeImageGif ) != 0 &&
       
   845                     aMimeType->Des8().CompareF( KMsgMimeImagePng ) != 0 &&
       
   846                     aMimeType->Des8().CompareF( KMsgMimeTextPlain ) != 0 )
       
   847                     {
       
   848                     // Supported types: jpeg, png, gif, plain text
       
   849                     result = EFalse;
       
   850                     }
       
   851                 }
       
   852                 break;   
       
   853             case KSenduiMtmAudioMessageUidValue:
       
   854                 {
       
   855                 if( aMimeType->Des8().CompareF( KMsgMimeAudioAmr ) != 0 ||
       
   856                     aMessageData->BodyText()->DocumentLength() > 0 )
       
   857                     {
       
   858                     // Does not allow other than amr attachment and empty bodytext
       
   859                     result = EFalse;
       
   860                     }
       
   861                 }    
       
   862                 break;    
       
   863             case KDrmLinkSenderValue:
       
   864                 {
       
   865                 // Check OMA DRM level
       
   866 
       
   867                 TInt drmMethod = 0;
       
   868                 CDRMHelper::TDRMHelperOMALevel omaDRMLevel;
       
   869                 CDRMHelper* drmHelper = NULL;
       
   870                 TRAPD( error, drmHelper = CDRMHelper::NewL( iFs ) );
       
   871                 if ( error != KErrNone )
       
   872                     {
       
   873                     return error;
       
   874                     }
       
   875                 error = drmHelper->SupportedDRMMethods2( drmMethod, omaDRMLevel );
       
   876                 if ( !(omaDRMLevel & CDRMHelper::EOMA_2_0 ))
       
   877                      {
       
   878                      result = EFalse;
       
   879                      break;
       
   880                      }
       
   881                 delete drmHelper;
       
   882 
       
   883 
       
   884                 if ( attachmentPaths.Count() )
       
   885                     {
       
   886                     RFile handle = SendUiUtils::OpenFileHandleL( attachmentPaths.MdcaPoint(0), iFs );
       
   887                     CleanupClosePushL( handle );
       
   888                     result = SendUiUtils::HasContentUrlL( handle );
       
   889                     CleanupStack::PopAndDestroy( &handle );
       
   890                     }
       
   891                 else
       
   892                     {
       
   893                     result = SendUiUtils::HasContentUrlL( const_cast<RFile&>( attachments[0] ) );
       
   894                     }
       
   895                 }
       
   896                 break;
       
   897             default:
       
   898                 // Should never end up here
       
   899                 break;
       
   900             }
       
   901      
       
   902         return result;        
       
   903         }
       
   904     else if ( attachmentCount > 1  )
       
   905         {
       
   906         if ( aServiceUid == KDrmLinkSender ||
       
   907              aServiceUid == KSenduiMtmPostcardUid ||
       
   908              aServiceUid == KSenduiMtmAudioMessageUid ||
       
   909              aServiceUid == KSenduiMtmSmsUid )
       
   910             {
       
   911             // Currently supports sending of one file only
       
   912             // or no files (SMS)
       
   913             return EFalse;
       
   914             }
       
   915         return ETrue;
       
   916         }
       
   917    
       
   918    // Should never end up here
       
   919    return ETrue;
       
   920    }
       
   921 
       
   922 // -----------------------------------------------------------------------------
       
   923 // CSendUiImpl::FilterServicesL
       
   924 // 
       
   925 // (other items were commented in a header).
       
   926 // -----------------------------------------------------------------------------
       
   927 //
       
   928 void CSendUiImpl::FilterServicesL(
       
   929     CDesCArrayFlat&         aListItems,
       
   930     CArrayFix<TUid>&        aListItemUids,
       
   931     TSendingCapabilities    aRequiredCapabilities,
       
   932     const CMessageData*     aMessageData,
       
   933     CSendUi::TSendUiMenuType    aMenuType  )
       
   934     {
       
   935     TInt i = 0;
       
   936     TInt cc = 0;
       
   937     TBool dimService = EFalse;
       
   938 	TDataType* mimeType = NULL;
       
   939 	TInt cleanupItems(0);
       
   940 	
       
   941 	 if(iEmailFramework)
       
   942 	     {
       
   943 	     if(!IsMailboxAvailableL())
       
   944 	         iServicesToDim->AppendL(KSenduiMtmSmtpUid);
       
   945 	     }
       
   946 	    
       
   947     // Filter some services away if there is no content to be send.
       
   948     if ( !aMessageData )
       
   949         {
       
   950         iServicesToDim->AppendL( KDrmLinkSender );
       
   951         iServicesToDim->AppendL( KMmsDirectUpload );
       
   952         iServicesToDim->AppendL( KMmsIndirectUpload );
       
   953         iServicesToDim->AppendL( KShareOnline );
       
   954         }
       
   955     else if ( aMessageData->AttachmentArray().Count() == 1
       
   956             || aMessageData->AttachmentHandleArray().Count() == 1 )
       
   957     	{
       
   958     	// CanSendContent can recycle these in mime type resolving
       
   959     	// for all services that have attachments
       
   960 		mimeType = new (ELeave) TDataType();
       
   961 		CleanupStack::PushL( mimeType );
       
   962 		cleanupItems++;
       
   963 				
       
   964 	    if ( aMessageData->AttachmentArray().Count() )
       
   965             {
       
   966             RFile handle = SendUiUtils::OpenFileHandleL(
       
   967                 aMessageData->AttachmentArray().MdcaPoint( 0 ), iFs );
       
   968             CleanupClosePushL( handle );
       
   969             SendUiUtils::ResolveMimeTypeL( handle, *mimeType );
       
   970             CleanupStack::PopAndDestroy( &handle );
       
   971             }
       
   972         else
       
   973             {
       
   974             SendUiUtils::ResolveMimeTypeL( aMessageData->AttachmentHandleArray()[0], *mimeType );
       
   975             }
       
   976     	}
       
   977     TBool addMailService = EFalse;
       
   978     TUid integratedEmailClientMtmUid;
       
   979 		
       
   980     if ( iEmailClientIntegration )
       
   981     	{
       
   982     	CRepository* repository = NULL;
       
   983     	TInt mtmPluginID = 0;
       
   984     	TRAPD( ret, repository = CRepository::NewL( KCRUidSelectableDefaultEmailSettings ) );
       
   985     	
       
   986     	if(ret == KErrNone)
       
   987     	    {
       
   988     	    //Get Email application mtm plugin ID
       
   989     	    repository->Get( KIntegratedEmailAppMtmPluginId, mtmPluginID ); 
       
   990     	    }
       
   991 
       
   992     	delete repository;
       
   993     	integratedEmailClientMtmUid = TUid::Uid(mtmPluginID);
       
   994     	for( i = 0 ; i < iSendingServices.Count(); i++ )
       
   995     		{
       
   996     		TUid serviceUid = iSendingServices[i]->ServiceId();
       
   997     		// Check if it is found in sendingServices and it's valid, then hide
       
   998     		if ( integratedEmailClientMtmUid == iSendingServices[i]->ServiceId() && 
       
   999     				CheckServiceCapabilities( serviceUid, aRequiredCapabilities ) &&
       
  1000     				CanSendContentL( serviceUid, 
       
  1001     							     iSendingServices[i]->ServiceProviderId(), 
       
  1002     							     aMessageData, mimeType ) )
       
  1003     			{
       
  1004     			addMailService = ETrue;
       
  1005     			}
       
  1006     		}
       
  1007     	
       
  1008     	}
       
  1009 
       
  1010     // Filter available ECom services and add to list item array.
       
  1011     // Capability based filtering: CheckServiceCapabilities
       
  1012     // Content based filtering: CanSendContentL
       
  1013     // "dimmable array" filtering: done here
       
  1014     TInt serviceFeatures;
       
  1015     for( i = 0 ; i < iSendingServices.Count(); i++ )
       
  1016         {
       
  1017         dimService = EFalse;
       
  1018         TUid serviceUid = iSendingServices[i]->ServiceId();
       
  1019         TUid serviceProviderUid = iSendingServices[i]->ServiceProviderId();
       
  1020         
       
  1021         if ( iSendingServices[i]->ServiceMenuName() == KNullDesC )
       
  1022             {
       
  1023             dimService = ETrue;
       
  1024             }
       
  1025         
       
  1026         TUid serviceTechnologyType = iSendingServices[i]->TechnologyTypeId();
       
  1027         TUid dimServiceUid;
       
  1028         for ( cc = 0; cc < iServicesToDim->Count(); cc++ )
       
  1029             {
       
  1030 			dimServiceUid = (*iServicesToDim)[cc];
       
  1031             if ( dimServiceUid == serviceUid 
       
  1032             || dimServiceUid == serviceProviderUid
       
  1033             || dimServiceUid == serviceTechnologyType 
       
  1034             )
       
  1035                 {
       
  1036                 dimService = ETrue;
       
  1037                 break;
       
  1038                 }
       
  1039             }
       
  1040         if ( iEmailClientIntegration )
       
  1041             {
       
  1042             //Hide Email application (not the platform email) from "send" menu
       
  1043             if( integratedEmailClientMtmUid == iSendingServices[i]->ServiceId() )
       
  1044                 {
       
  1045                 dimService = ETrue;
       
  1046                 }  
       
  1047             }
       
  1048 		serviceFeatures = iSendingServices[i]->ServiceFeatures();
       
  1049         if ( iEmailClientIntegration )
       
  1050         	{
       
  1051         	//If there is a mailbox created by integrated mail client then 
       
  1052         	//put SMTP MTM ("Email") in the "send" menu, by changing the 
       
  1053         	//serviceFeature    
       
  1054         	if ( addMailService && 
       
  1055         		 ( iSendingServices[i]->ServiceId() == KUidMsgTypeSMTP ) )
       
  1056         		{
       
  1057         		serviceFeatures = 0;
       
  1058         		addMailService = EFalse; //MailService must be added only once
       
  1059         		}
       
  1060         	}  
       
  1061         
       
  1062         //Check if the sending service is some third party email provider than hide from the Send menu.
       
  1063         if( iEmailFramework  && (iSendingServices[i]->TechnologyTypeId() == KMailTechnologyTypeUid))
       
  1064             {
       
  1065             if(IsThirdPartyMailService(iSendingServices[i]->ServiceId()))
       
  1066                 dimService = ETrue;
       
  1067             }
       
  1068         
       
  1069         if ( !dimService &&
       
  1070              !( serviceFeatures & CSendingServiceInfo::EServiceInValid ) &&
       
  1071              !( serviceFeatures & CSendingServiceInfo::EServiceHidden )
       
  1072              &&  CheckServiceCapabilities( serviceUid, aRequiredCapabilities ) &&
       
  1073              CanSendContentL( serviceUid, serviceProviderUid, aMessageData, mimeType ) )
       
  1074             {
       
  1075             if ( aMenuType == CSendUi::ESendMenu )
       
  1076                 {
       
  1077                 aListItems.AppendL(iSendingServices[i]->ServiceMenuName() );
       
  1078                 }
       
  1079             else if ( aMenuType == CSendUi::EWriteMenu )
       
  1080                 {
       
  1081                 aListItems.AppendL(iSendingServices[i]->ServiceName() );
       
  1082                 }
       
  1083 
       
  1084             aListItemUids.AppendL( serviceUid );
       
  1085             }
       
  1086         }
       
  1087     CleanupStack::PopAndDestroy( cleanupItems );
       
  1088     }
       
  1089 
       
  1090 // -----------------------------------------------------------------------------
       
  1091 // SortListL
       
  1092 // Sets ECom services to correct positions in "Send"-list query.
       
  1093 // -----------------------------------------------------------------------------
       
  1094 //
       
  1095 void CSendUiImpl::SortListL(
       
  1096     CDesCArrayFlat&     aListItems,
       
  1097     CArrayFix<TUid>&    aListItemUids )
       
  1098     {
       
  1099     TInt insertIndex(0);
       
  1100     TUid positionUid;   
       
  1101     TInt j;
       
  1102     // set the services into correct order. The order is predefined in the resources.
       
  1103     for ( TInt i = 0; i < iSendUiServicesOrderArray->Count() ; i++ )
       
  1104         {
       
  1105         positionUid = TUid::Uid( (*iSendUiServicesOrderArray)[i] );
       
  1106         for (j = insertIndex; j < aListItems.Count(); j++ )
       
  1107             {
       
  1108             TUid tmp = aListItemUids[j];
       
  1109             if ( positionUid == aListItemUids[j] ) 
       
  1110                 {
       
  1111                 if ( j >= insertIndex )
       
  1112                     {
       
  1113                     HBufC* serviceName = aListItems[j].AllocL();
       
  1114                     CleanupStack::PushL( serviceName );
       
  1115 
       
  1116                     aListItemUids.Delete( j );
       
  1117                     aListItems.Delete( j );
       
  1118 
       
  1119                     aListItemUids.InsertL( insertIndex, positionUid );
       
  1120                     aListItems.InsertL( insertIndex, *serviceName );
       
  1121                     CleanupStack::PopAndDestroy( serviceName );
       
  1122                     insertIndex++;      
       
  1123                     }
       
  1124                 else
       
  1125                     {
       
  1126                     // service already on the right place. Next.
       
  1127                     insertIndex++;  
       
  1128                     }
       
  1129                     
       
  1130                 }
       
  1131             }
       
  1132         }
       
  1133     }
       
  1134 
       
  1135 
       
  1136 // ---------------------------------------------------------
       
  1137 // ResetIsSending
       
  1138 // Resets sending state flag.
       
  1139 // ---------------------------------------------------------
       
  1140 //    
       
  1141 void CSendUiImpl::ResetIsSending( TAny* aAny )
       
  1142     {
       
  1143     *( (TBool*)aAny ) = EFalse;
       
  1144     }
       
  1145 
       
  1146 // -----------------------------------------------------------------------------
       
  1147 // CheckServiceCapabilities
       
  1148 // Compares ECom service sending capabilities to required capabilities.
       
  1149 // (other items were commented in a header).
       
  1150 // -----------------------------------------------------------------------------
       
  1151 //
       
  1152 TBool CSendUiImpl::CheckServiceCapabilities(
       
  1153     TUid                    aServiceUid,
       
  1154     TSendingCapabilities    aRequiredCapabilities )
       
  1155     {
       
  1156     TInt i = 0;
       
  1157     TSendingCapabilities serviceCapabilities;
       
  1158 
       
  1159     // No capabilities defined, uses content-based filtering
       
  1160     // or no capabilities required from service
       
  1161     if ( aServiceUid == KDrmLinkSender 
       
  1162          || aRequiredCapabilities.iFlags == TSendingCapabilities::EAllServices )
       
  1163         { 
       
  1164         return ETrue;
       
  1165         }
       
  1166 
       
  1167     i = ResolveServiceIndex( aServiceUid );
       
  1168 
       
  1169     if ( i != KErrNotFound )
       
  1170         {
       
  1171         return QueryCapabilities( i, aRequiredCapabilities );  
       
  1172         }
       
  1173     else
       
  1174         {
       
  1175         return EFalse;          
       
  1176         }
       
  1177     }
       
  1178 
       
  1179 // -----------------------------------------------------------------------------
       
  1180 // CSendUiImpl
       
  1181 // C++ default constructor can NOT contain any code, that
       
  1182 // might leave.
       
  1183 // -----------------------------------------------------------------------------
       
  1184 //
       
  1185 CSendUiImpl::CSendUiImpl()
       
  1186     :  iCoeEnv( CCoeEnv::Static() ),
       
  1187         iFs( iCoeEnv->FsSession() ),
       
  1188         iResourceLoader( *iCoeEnv ),
       
  1189         iEmailFramework(EFalse)
       
  1190         
       
  1191     {
       
  1192     }
       
  1193 
       
  1194 // -----------------------------------------------------------------------------
       
  1195 // CSendUiImpl::FeatureStatus
       
  1196 // -----------------------------------------------------------------------------
       
  1197 //
       
  1198 void CSendUiImpl::FeatureStatus( TInt aFeature, TInt &aNewFeatures, TInt aFeatureFlag )
       
  1199     {
       
  1200     if ( FeatureManager::FeatureSupported( aFeature ) )
       
  1201         {
       
  1202         // If Postcard only is supported,     aFeatureFlag is 0x00000001 ==> aNewFeatures == 0x00000001
       
  1203         // If Audio message is also supported aFeatureFlag is 0x00000002 ==> aNewFeatures == 0x00000003
       
  1204         // If MMSUpload is also supported,    aFeatureFlag is 0x00000004 ==> aNewFeatures == 0x00000007
       
  1205         aNewFeatures |= aFeatureFlag;
       
  1206         }
       
  1207     }
       
  1208 // ConstructL
       
  1209 // Symbian 2nd phase constructor can leave.
       
  1210 // -----------------------------------------------------------------------------
       
  1211 //
       
  1212 void CSendUiImpl::ConstructL()
       
  1213     {
       
  1214     iSingleton = CSendUiSingleton::NewL();
       
  1215     //User::LeaveIfError( iFs.Connect() );
       
  1216     iFs.ShareProtected();
       
  1217 
       
  1218     TParse* fp = new(ELeave) TParse(); 
       
  1219     fp->Set( KSendUiResourceFileName, &KDC_RESOURCE_FILES_DIR, NULL );
       
  1220     iResourceFileName = fp->FullName();
       
  1221     delete fp;
       
  1222     fp = NULL;
       
  1223     
       
  1224     iResourceLoader.OpenL( iResourceFileName );
       
  1225 
       
  1226     // Check for server launch
       
  1227     RProcess process;
       
  1228     TUid hostId = process.SecureId();
       
  1229     if ( hostId == KSendUiLauncherAppUid ) 
       
  1230         {
       
  1231         iServerAppLaunch = ETrue;
       
  1232         }
       
  1233    else
       
  1234         {
       
  1235         iServerAppLaunch = EFalse;
       
  1236         iSendUiServicesOrderArray = 
       
  1237             new ( ELeave ) CArrayFixFlat<TInt32>( KSendUiServiceOrderArrayGranularity );
       
  1238 
       
  1239         TResourceReader reader;
       
  1240         iCoeEnv->CreateResourceReaderLC( reader, R_SENDUISERVICEORDER_ARRAY );
       
  1241         const TInt count = reader.ReadInt16();
       
  1242         for ( TInt loop = 0; loop < count; loop++ )
       
  1243             {
       
  1244             iSendUiServicesOrderArray->AppendL( reader.ReadInt32() );
       
  1245             }
       
  1246         CleanupStack::PopAndDestroy( ); // reader 
       
  1247         }
       
  1248 
       
  1249     iPropertyObserver = CPropertyObserver::NewL( this );
       
  1250     TRAPD( err, GetServicesL() );
       
  1251     
       
  1252     if ( err )
       
  1253         {
       
  1254 #ifdef _DEBUG
       
  1255         TBuf<256> buf;
       
  1256         buf.Format(_L("SendUi err"));
       
  1257         User::InfoPrint(buf);
       
  1258         LOGTEXT2(_L("Error %d while loading CenRep"), err );
       
  1259 #endif
       
  1260         return;
       
  1261         }
       
  1262     iServicesToDim = new (ELeave) CArrayFixFlat<TUid>( KArrayGranularity );
       
  1263     FeatureManager::InitializeLibL();
       
  1264     
       
  1265     if ( FeatureManager::FeatureSupported( KFeatureIdEmailMceIntegration ) )
       
  1266     	{
       
  1267 
       
  1268     	iEmailClientIntegration = ETrue;
       
  1269     	}
       
  1270     else
       
  1271     	{
       
  1272 
       
  1273     	iEmailClientIntegration = EFalse;
       
  1274     	}   
       
  1275     if ( FeatureManager::FeatureSupported( KFeatureIdFfEmailFramework ) )
       
  1276     {
       
  1277       iEmailFramework = ETrue;
       
  1278     } 
       
  1279     FeatureManager::UnInitializeLib();
       
  1280     }
       
  1281 // -----------------------------------------------------------------------------
       
  1282 // CSendUiImpl::IsMailboxAvailableL
       
  1283 // -----------------------------------------------------------------------------
       
  1284 //
       
  1285 TBool CSendUiImpl::IsMailboxAvailableL(void)
       
  1286 {
       
  1287     TBool mailbox = EFalse;
       
  1288     TBool retval = EFalse;
       
  1289     
       
  1290     CMsvSession& msv = iSingleton->MsvSessionL();
       
  1291     CMsvEntry* entry = msv.GetEntryL( KMsvRootIndexEntryId );
       
  1292     CleanupStack::PushL( entry );
       
  1293     
       
  1294     entry->SetSortTypeL( TMsvSelectionOrdering(
       
  1295                              KMsvGroupByType | KMsvGroupByStandardFolders,
       
  1296                              EMsvSortByDetailsReverse, ETrue ) );
       
  1297 
       
  1298      // Add others
       
  1299      for ( TInt cc = entry->Count(); --cc >= 0; )
       
  1300          {
       
  1301          TMsvEntry tentry2 = (*entry)[cc];
       
  1302 
       
  1303          if ( tentry2.iType.iUid == KUidMsvServiceEntryValue &&
       
  1304               tentry2.Id() != KMsvLocalServiceIndexEntryIdValue )
       
  1305              {
       
  1306              if ( IsEmailAppendableL(tentry2) )
       
  1307                  {
       
  1308                      mailbox = ETrue;
       
  1309                      break;
       
  1310                  }
       
  1311              }
       
  1312          }
       
  1313      
       
  1314          CleanupStack::PopAndDestroy( entry );
       
  1315 
       
  1316          // if accounts defined, 
       
  1317          if ( mailbox )
       
  1318              {
       
  1319              retval =  mailbox;
       
  1320              }   
       
  1321          
       
  1322      return mailbox; 
       
  1323 }
       
  1324 
       
  1325 // -----------------------------------------------------------------------------
       
  1326 // IsThirdPartyMailService
       
  1327 // Check if any Third Party Email Serivce is present or not
       
  1328 // -----------------------------------------------------------------------------
       
  1329 //
       
  1330 
       
  1331 TBool CSendUiImpl::IsThirdPartyMailService( TUid aUid )
       
  1332     {
       
  1333     //If the Uid is other than SMTP and Cmail
       
  1334     //than is a Third Party service
       
  1335       if((aUid !=  KUidMsgTypeSMTP)&&
       
  1336        ( aUid.iUid != KUidMsgTypeFsMtmVal ) )
       
  1337         {
       
  1338         return ETrue;
       
  1339         }
       
  1340       else
       
  1341         return EFalse;
       
  1342     }
       
  1343 
       
  1344 // -----------------------------------------------------------------------------
       
  1345 // IsEmailAppendableL
       
  1346 // Check if Email entry is valid to be counted
       
  1347 // -----------------------------------------------------------------------------
       
  1348 //
       
  1349 
       
  1350 TBool CSendUiImpl::IsEmailAppendableL(TMsvEntry atentry)
       
  1351     {
       
  1352     TBool appendEmail = EFalse;
       
  1353 
       
  1354     if ( atentry.Visible() )
       
  1355         {
       
  1356         appendEmail = ETrue;
       
  1357         }
       
  1358     else
       
  1359         {
       
  1360         if ( iSingleton->MtmUiDataRegistryL().IsPresent( atentry.iMtm ) &&
       
  1361                 iSingleton->MtmUiDataRegistryL().IsPresent( KUidMsgTypePOP3 ) )
       
  1362             {
       
  1363             TUid mailMTMTechType =
       
  1364             iSingleton->MtmUiDataRegistryL().TechnologyTypeUid( KUidMsgTypePOP3 );
       
  1365             if( iSingleton->MtmUiDataRegistryL().TechnologyTypeUid( atentry.iMtm ) ==
       
  1366                                                 mailMTMTechType )
       
  1367                 {
       
  1368                 appendEmail = ETrue;
       
  1369                 }
       
  1370             }
       
  1371         }
       
  1372     return appendEmail;
       
  1373     }
       
  1374 
       
  1375 // end of file
       
  1376