messagingappbase/sendui/mmsdirectupload/src/CMmsDirectUpload.cpp
branchRCL_3
changeset 27 7fdbb852d323
equal deleted inserted replaced
26:ebe688cedc25 27:7fdbb852d323
       
     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:   Provides MMS direct upload service.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    <CSendingServiceInfo.h>
       
    22 #include    <SendUiConsts.h>
       
    23 #include    <CMessageData.h>
       
    24 #include    <TSendingCapabilities.h>
       
    25 #include    <bautils.h>                        // BaflUtils
       
    26 #include    <AknQueryDialog.h>                 // Query dialog
       
    27 #include    <FeatMgr.h>
       
    28 #include    <StringLoader.h>
       
    29 #include    <MmsDirectUploadUi.rsg>
       
    30 #include    <Mmserrors.h>
       
    31 #include    <data_caging_path_literals.hrh>
       
    32 #include    <Sendnorm.rsg>
       
    33 #include    <aknnotewrappers.h>                // Error note
       
    34 #include    <senduisingleton.h>
       
    35 
       
    36 #include    "CMmsDirectUpload.h"
       
    37 #include    "MDUSyncCreateAndSend.h"
       
    38 #include    "SendUiFileRightsEngine.h"
       
    39 #include    "CSendUiAttachment.h"
       
    40 
       
    41 // CONSTANTS
       
    42 
       
    43 const TInt KMmsUploadServiceCount       = 4;
       
    44 const TInt KMmsDirectUploadService      = 1;
       
    45 const TInt KMaxServiceAddressLength     = 512;
       
    46 const TInt KMaxServiceNameLength        = 128;
       
    47 const TInt KMaxServiceMenuNameLength    = 128;
       
    48 
       
    49 _LIT( KMmsDirectUploadUiResource, "MmsDirectUploadUi.rsc");
       
    50 
       
    51 // ============================ MEMBER FUNCTIONS ===============================
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CMmsDirectUpload::CMmsDirectUpload
       
    55 // C++ default constructor can NOT contain any code, that
       
    56 // might leave.
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CMmsDirectUpload::CMmsDirectUpload( CCoeEnv& aCoeEnv, CSendUiSingleton& aSingleton ) :
       
    60 	CSendingService( aCoeEnv, aSingleton ),
       
    61     iResourceLoader( iCoeEnv )
       
    62     {
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CMmsDirectUpload::ConstructL
       
    67 // Symbian 2nd phase constructor can leave.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 void CMmsDirectUpload::ConstructL()
       
    71     {
       
    72     
       
    73     ReadServiceDataL();
       
    74 
       
    75     // Load UI resource file.
       
    76     TFileName resourceFile;
       
    77     TParse* fp = new(ELeave) TParse(); 
       
    78     fp->Set( KMmsDirectUploadUiResource, &KDC_RESOURCE_FILES_DIR, NULL );
       
    79     resourceFile = fp->FullName();
       
    80     delete fp;
       
    81     fp = NULL;
       
    82     
       
    83     iResourceLoader.OpenL( resourceFile );
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CMmsDirectUpload::NewL
       
    88 // Two-phased constructor.
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 CMmsDirectUpload* CMmsDirectUpload::NewL( TSendingServiceParams* aParams )
       
    92     {
       
    93     CMmsDirectUpload* self = new(ELeave) CMmsDirectUpload( aParams->iCoeEnv, aParams->iSingleton ); 
       
    94 
       
    95     CleanupStack::PushL(self);
       
    96     self->ConstructL();
       
    97     CleanupStack::Pop(self);
       
    98 
       
    99     return self;
       
   100     }
       
   101 
       
   102 // Destructor
       
   103 CMmsDirectUpload::~CMmsDirectUpload()
       
   104     {
       
   105     // Unload UI resource file.
       
   106     iResourceLoader.Close();
       
   107     iServiceArray.ResetAndDestroy();
       
   108     iServiceArray.Close();
       
   109     }
       
   110 
       
   111 
       
   112 // ---------------------------------------------------------
       
   113 // CMmsDirectUpload::ServiceProviderId
       
   114 // Returns the id of the service provider.
       
   115 // (other items were commented in a header).
       
   116 // ---------------------------------------------------------
       
   117 //
       
   118 TUid CMmsDirectUpload::ServiceProviderId() const
       
   119     {
       
   120     return KMmsDirectUpload;
       
   121     }
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CMmsDirectUpload::PopulateServicesListL
       
   125 // Populates given list with the services provided by this plugin.
       
   126 // The ownership of the pointed objects remains.
       
   127 // (other items were commented in a header).
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 void CMmsDirectUpload::PopulateServicesListL(
       
   131     RPointerArray<CSendingServiceInfo>& aList )
       
   132     {
       
   133     CleanupClosePushL( aList );
       
   134     for ( TInt cc = 0; cc < iServiceArray.Count(); cc++ )
       
   135         {
       
   136         User::LeaveIfError( aList.Append( iServiceArray[cc] ) );         
       
   137         }
       
   138     CleanupStack::Pop( &aList );
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CMmsDirectUpload::CreateAndSendMessageL
       
   143 // Creates to outbox as many MMS messages as there are files to be send.
       
   144 // (other items were commented in a header).
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 void CMmsDirectUpload::CreateAndSendMessageL(
       
   148     TUid                    aServiceUid,
       
   149     const CMessageData*     aMessageData,
       
   150     TBool /*aLaunchEditorEmbedded */)
       
   151     {
       
   152     TInt i = 0;
       
   153     
       
   154     if ( !aMessageData || ( iServiceArray.Count() == 0 ) )
       
   155         {
       
   156         return;
       
   157         }
       
   158     
       
   159     CArrayPtrFlat<CSendUiAttachment>* attachments;
       
   160 	TInt cleanupItems = 0;
       
   161     // Get attachments
       
   162     attachments = CSendUiAttachment::InitAttachmentArrayLCC( 
       
   163         aMessageData->AttachmentArray(), 
       
   164         aMessageData->AttachmentHandleArray(),
       
   165         iCoeEnv.FsSession() );
       
   166     cleanupItems += 2;
       
   167 		
       
   168     if ( !ValidateAttachmentsL( attachments ) )
       
   169         { // User canceled sending.
       
   170         
       
   171         // Cleanup: attachments, *attachments
       
   172         CleanupStack::PopAndDestroy( cleanupItems );
       
   173         return;
       
   174         }
       
   175 
       
   176     const CRichText* bodyText = aMessageData->BodyText();
       
   177     if ( bodyText->DocumentLength() > 0 )
       
   178         {
       
   179         CSendUiAttachment* atta = CSendUiAttachment::NewLC( *bodyText, iCoeEnv.FsSession() );
       
   180         attachments->AppendL( atta );
       
   181         CleanupStack::Pop( atta );
       
   182         }
       
   183     TInt attachmentCount = attachments->Count();
       
   184 
       
   185     // No valid attachments
       
   186     if ( attachmentCount <= 0 )
       
   187         {
       
   188         CleanupStack::PopAndDestroy( cleanupItems  ); // *attachmemts, attachments
       
   189         return;
       
   190         }
       
   191 
       
   192     // Ask users opinion about sending files in separate messages or canceling
       
   193     // the actual sending operation.
       
   194     if ( attachmentCount > 1 )
       
   195         {
       
   196         if ( !ShowConfirmationQueryL( R_MMS_DIRECT_UPLOAD_SEND_MESSAGES_QUERY,
       
   197             R_MMS_DIRECT_UPLOAD_SEND_MESSAGES, attachmentCount ) )
       
   198             {
       
   199             CleanupStack::PopAndDestroy( cleanupItems );
       
   200             return;
       
   201             }
       
   202         }
       
   203 
       
   204    // Get service name
       
   205     HBufC* serviceName = NULL;
       
   206     for ( i = 0; i < iServiceArray.Count(); i++)
       
   207         {
       
   208         if ( (*iServiceArray[i]).ServiceId() == aServiceUid)
       
   209             {
       
   210             serviceName = ((*iServiceArray[i]).ServiceName()).AllocLC();
       
   211             cleanupItems++;
       
   212             if ( serviceName->Length() == 0 )
       
   213                 {
       
   214                 User::Leave( KErrNotFound );
       
   215                 }
       
   216             }
       
   217         }
       
   218 
       
   219     // Get service address
       
   220     HBufC*  serviceAddress = NULL;
       
   221     for ( i = 0; i < iServiceArray.Count(); i++)
       
   222         {
       
   223         if ( (*iServiceArray[i]).ServiceId() == aServiceUid)
       
   224             {
       
   225             serviceAddress = (*iServiceArray[i]).ServiceAddress().AllocLC();
       
   226             cleanupItems++;
       
   227             if ( serviceAddress->Length() == 0 )
       
   228                 {
       
   229                 User::Leave( KErrNotFound );
       
   230                 }
       
   231             }
       
   232         }
       
   233 
       
   234     // Create and send messages        
       
   235     CMDUSyncCreateAndSend* messageSender = CMDUSyncCreateAndSend::NewLC( iCoeEnv, iSingleton );
       
   236     cleanupItems++;
       
   237     
       
   238     TRAPD( error, messageSender->CreateAndSendL(
       
   239         attachments,
       
   240         *serviceAddress,
       
   241         *serviceName,
       
   242         iMaxMsgSize ) );
       
   243     // KErrCompletion is received, if for some attachments information note was shown
       
   244     if ( !( error == KErrNone || error == KErrCompletion ))
       
   245         {
       
   246         ErrorHandlerL( error, attachmentCount );
       
   247         }
       
   248 
       
   249     if( messageSender->Error() )
       
   250         {
       
   251         ErrorHandlerL( messageSender->Error(), attachmentCount );
       
   252         }
       
   253     else
       
   254         {
       
   255         // Get compression results
       
   256         TInt compressionOk = 0;
       
   257         TInt compressionFail = 0;
       
   258         
       
   259         messageSender->CompressionResults( compressionOk, compressionFail );
       
   260         
       
   261         if ( compressionFail > 0 )
       
   262             {
       
   263             ResolveCompressionQueryL(
       
   264                 attachmentCount, compressionFail );
       
   265             }
       
   266         }
       
   267     // Cleanup: serviceName, serviceAddress, messageSender, attachments, *attachments
       
   268     CleanupStack::PopAndDestroy( cleanupItems );
       
   269     }
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 // CMmsDirectUpload::ValidateAttachmentsL
       
   273 // Validates attachments for sending. DRM protection and MMS validity are
       
   274 // checked. DRM query and error note is shown if needed. Return value of
       
   275 // attachment arrays contains valid attachments. EFalse is returned if user
       
   276 // cancels sending, otherwise ETrue is returned.
       
   277 // (other items were commented in a header).
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 TBool CMmsDirectUpload::ValidateAttachmentsL(
       
   281     CArrayPtrFlat<CSendUiAttachment>* aAttachments )
       
   282     {
       
   283     TBool continueSending = ETrue;
       
   284    
       
   285     // Validate attachments and show query and error note if needed.
       
   286     if ( aAttachments->Count() > 0 )
       
   287         {
       
   288         CSendUiFileRightsEngine* fileRightsEngine =
       
   289             CSendUiFileRightsEngine::NewLC( iCoeEnv.FsSession() );
       
   290 
       
   291         fileRightsEngine->ConfirmDrmFileRightsL( aAttachments );
       
   292         fileRightsEngine->ConfirmMmsValidityL( aAttachments, KMmsDirectUpload );
       
   293 
       
   294         continueSending =
       
   295             fileRightsEngine->ShowDrmAndMmsInfoL( KMmsDirectUpload );
       
   296 
       
   297         CleanupStack::PopAndDestroy( fileRightsEngine );
       
   298         }
       
   299 
       
   300     return continueSending;
       
   301     }
       
   302 
       
   303 // -----------------------------------------------------------------------------
       
   304 // CMmsDirectUpload::ReadServiceDataL
       
   305 // Reads service names from resource file and addresses from shared data or 
       
   306 // from central repository.
       
   307 // (other items were commented in a header).
       
   308 // -----------------------------------------------------------------------------
       
   309 //
       
   310 void CMmsDirectUpload::ReadServiceDataL()
       
   311     {
       
   312     // Read the maximum MMS message size (bytes).
       
   313     CRepository* mmsRepository = CRepository::NewL( KCRUidMmsEngine );
       
   314     mmsRepository->Get( KMmsEngineMaximumSendSize, iMaxMsgSize );
       
   315     delete mmsRepository;
       
   316 
       
   317     CRepository* senduiRepository = CRepository::NewLC( KCRUidSendUi );
       
   318     TInt i = 0;
       
   319     // Go through services and get settings for direct upload services.
       
   320     // There can be 0-4 direct upload services configured.
       
   321     for ( i = 0; i < KMmsUploadServiceCount; i++)
       
   322         {
       
   323         TInt serviceType = 0;
       
   324         TInt err = senduiRepository->Get( KSUMmsUploadType1 + i , serviceType );
       
   325         
       
   326         // Get settings and store those to service array.
       
   327         if ( !err && serviceType == KMmsDirectUploadService )
       
   328             {
       
   329             CSendingServiceInfo* serviceInfo = CSendingServiceInfo::NewL();
       
   330             CleanupStack::PushL( serviceInfo );
       
   331 
       
   332             HBufC* serviceAddress = HBufC::NewLC( KMaxServiceAddressLength );
       
   333             TPtr serviceAddressPtr = serviceAddress->Des();
       
   334             User::LeaveIfError( senduiRepository->Get( KSUMmsUploadAddress1 + i , serviceAddressPtr ) );
       
   335             serviceInfo->SetServiceAddressL( serviceAddressPtr );
       
   336             CleanupStack::PopAndDestroy( serviceAddress );
       
   337 
       
   338             HBufC* serviceName = HBufC::NewLC( KMaxServiceNameLength );
       
   339             TPtr serviceNamePtr = serviceName->Des();
       
   340             User::LeaveIfError( senduiRepository->Get( KSUMmsUploadServiceName1 + i , serviceNamePtr ) );
       
   341             serviceInfo->SetServiceNameL( serviceNamePtr );
       
   342             CleanupStack::PopAndDestroy( serviceName );
       
   343             
       
   344             HBufC* serviceMenuName = HBufC::NewLC( KMaxServiceMenuNameLength );
       
   345             TPtr serviceMenuNamePtr = serviceMenuName->Des();
       
   346             User::LeaveIfError( senduiRepository->Get( KSUMmsUploadServiceMenuName1 + i , serviceMenuNamePtr ) );
       
   347             serviceInfo->SetServiceMenuNameL( serviceMenuNamePtr );
       
   348             CleanupStack::PopAndDestroy( serviceMenuName );
       
   349 
       
   350             // Set service type.
       
   351             serviceInfo->SetServiceProviderId( KMmsDirectUpload );
       
   352             serviceInfo->SetServiceFeatures( CSendingServiceInfo::EServiceCanSendDirectly );
       
   353 
       
   354             // Set sending capabilities.
       
   355             TSendingCapabilities capabilities = 
       
   356                 TSendingCapabilities( 0, KMaxTInt,
       
   357                     TSendingCapabilities::ESupportsAttachments );
       
   358 
       
   359             serviceInfo->SetServiceCapabilities( capabilities );
       
   360 
       
   361             TUid serviceId = KNullUid;
       
   362             switch ( i )
       
   363                 {
       
   364                 case 0:
       
   365                     {
       
   366                     serviceId = KMmsUploadService1Id;
       
   367                     break;
       
   368                     }
       
   369                 case 1:
       
   370                     {
       
   371                     serviceId = KMmsUploadService2Id;
       
   372                     break;
       
   373                     }
       
   374                 case 2:
       
   375                     {
       
   376                     serviceId = KMmsUploadService3Id;
       
   377                     break;
       
   378                     }
       
   379                 case 3:
       
   380                     {
       
   381                     serviceId = KMmsUploadService4Id;
       
   382                     break;
       
   383                     }
       
   384                 default:
       
   385                     break;
       
   386                 }
       
   387             serviceInfo->SetServiceId( serviceId );
       
   388 
       
   389             iServiceArray.Append( serviceInfo );
       
   390             CleanupStack::Pop( serviceInfo );
       
   391             }
       
   392         }
       
   393 
       
   394     CleanupStack::PopAndDestroy( senduiRepository );
       
   395     }
       
   396 
       
   397 // ---------------------------------------------------------
       
   398 // CMmsDirectUpload::ShowConfirmationQueryL
       
   399 // Shows confirmation query.
       
   400 // (other items were commented in a header).
       
   401 // ---------------------------------------------------------
       
   402 //
       
   403 TBool CMmsDirectUpload::ShowConfirmationQueryL(
       
   404     const TUint&    aQueryId,
       
   405     const TUint&    aQueryTextId,
       
   406     TInt            aQueryValue) const
       
   407     {
       
   408     HBufC* prompt = NULL;
       
   409 
       
   410     // Get text to be shown
       
   411     if ( aQueryValue )
       
   412         {
       
   413         prompt = StringLoader::LoadLC( aQueryTextId, aQueryValue );
       
   414         }
       
   415     else
       
   416         {
       
   417         prompt = StringLoader::LoadLC( aQueryTextId );
       
   418         }
       
   419 
       
   420     // Create dialog
       
   421     CAknQueryDialog* dlg = CAknQueryDialog::NewL( CAknQueryDialog::ENoTone );
       
   422 
       
   423     TInt result = dlg->ExecuteLD( aQueryId, prompt->Des() );
       
   424 
       
   425     CleanupStack::PopAndDestroy( prompt ); // prompt
       
   426 
       
   427     return ( result == EAknSoftkeyOk );
       
   428     }
       
   429 
       
   430 // ---------------------------------------------------------
       
   431 // CMmsDirectUpload::ErrorHandlerL
       
   432 // Show confirmation query to the user if images have been compressed.
       
   433 // (other items were commented in a header).
       
   434 // ---------------------------------------------------------
       
   435 //
       
   436 void CMmsDirectUpload::ErrorHandlerL( TInt aErr, TInt aFileCount ) const
       
   437     {
       
   438     if ( aErr )
       
   439         {
       
   440         switch ( aErr )
       
   441             {
       
   442             case KMmsErrorInvalidSettings:
       
   443             case KMmsErrorNoWAPAccessPoint:
       
   444             case KMmsErrorNoWapAp1:
       
   445                 {
       
   446                 ShowErrorNoteL( aFileCount > 1 ?
       
   447                     R_SENDUI_SETTINGS_NOT_OK_MANY : R_SENDUI_SETTINGS_NOT_OK );
       
   448                 break;
       
   449                 }
       
   450             default:
       
   451                 {
       
   452                 ShowConfirmationQueryL( R_MMS_DIRECT_UPLOAD_CONFIRMABLE_INFO,
       
   453                     aFileCount > 1 ? 
       
   454                     R_MMS_DIRECT_UPLOAD_CREATION_FAILED_ALL:
       
   455                     R_MMS_DIRECT_UPLOAD_CREATION_FAILED_ONE);         
       
   456                 break;
       
   457                 }
       
   458             }
       
   459         }
       
   460     }
       
   461 
       
   462 // ---------------------------------------------------------
       
   463 // CMmsDirectUpload::ResolveCompressionQueryL
       
   464 // Show confirmation query to the user if images have been compressed.
       
   465 // (other items were commented in a header).
       
   466 // ---------------------------------------------------------
       
   467 //
       
   468 void CMmsDirectUpload::ResolveCompressionQueryL(
       
   469     TInt aFileCount,
       
   470     TInt aCompressionFail ) const
       
   471     {
       
   472     // Show confirmation query to the user if images have been compressed.
       
   473     if ( aCompressionFail > 0 )
       
   474         {
       
   475         // Compression has failed for all files
       
   476         if ( aFileCount == aCompressionFail )
       
   477             {
       
   478             ShowConfirmationQueryL( R_MMS_DIRECT_UPLOAD_CONFIRMABLE_INFO,
       
   479                 aCompressionFail > 1 ? 
       
   480                     R_MMS_DIRECT_UPLOAD_CREATION_FAILED_ALL:
       
   481                     R_MMS_DIRECT_UPLOAD_CREATION_FAILED_ONE);
       
   482             }
       
   483         else
       
   484             {
       
   485             ShowConfirmationQueryL( R_MMS_DIRECT_UPLOAD_CONFIRMABLE_INFO,
       
   486                 R_MMS_DIRECT_UPLOAD_CREATION_FAILED_SOME );
       
   487             }
       
   488         }
       
   489     }
       
   490 
       
   491 // ---------------------------------------------------------
       
   492 // CMmsDirectUpload::ShowErrorNoteL
       
   493 // Show error note to the user.
       
   494 // (other items were commented in a header).
       
   495 // ---------------------------------------------------------
       
   496 //   
       
   497 void CMmsDirectUpload::ShowErrorNoteL( TInt aResourceId ) const
       
   498     {
       
   499     HBufC* text = static_cast<CEikonEnv&>( iCoeEnv ).AllocReadResourceLC( aResourceId );
       
   500 
       
   501     CAknErrorNote* note = new (ELeave) CAknErrorNote;
       
   502     note->ExecuteLD(*text);
       
   503 
       
   504     CleanupStack::PopAndDestroy( text ); // text
       
   505     }
       
   506     
       
   507 TUid CMmsDirectUpload::TechnologyTypeId( ) const
       
   508 {
       
   509     return TUid::Uid( KSenduiTechnologyMmsUidValue );
       
   510 }
       
   511 
       
   512 //  End of File