messagingappbase/sendui/mmsdirectupload/src/CMmsDirectUpload.cpp
changeset 0 72b543305e3a
child 16 e00582ce7ecd
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     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     for ( TInt cc = 0; cc < iServiceArray.Count(); cc++ )
       
   134         {
       
   135         User::LeaveIfError( aList.Append( iServiceArray[cc] ) );         
       
   136         }
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CMmsDirectUpload::CreateAndSendMessageL
       
   141 // Creates to outbox as many MMS messages as there are files to be send.
       
   142 // (other items were commented in a header).
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 void CMmsDirectUpload::CreateAndSendMessageL(
       
   146     TUid                    aServiceUid,
       
   147     const CMessageData*     aMessageData,
       
   148     TBool /*aLaunchEditorEmbedded */)
       
   149     {
       
   150     TInt i = 0;
       
   151     
       
   152     if ( !aMessageData || ( iServiceArray.Count() == 0 ) )
       
   153         {
       
   154         return;
       
   155         }
       
   156     
       
   157     CArrayPtrFlat<CSendUiAttachment>* attachments;
       
   158 	TInt cleanupItems = 0;
       
   159     // Get attachments
       
   160     attachments = CSendUiAttachment::InitAttachmentArrayLCC( 
       
   161         aMessageData->AttachmentArray(), 
       
   162         aMessageData->AttachmentHandleArray(),
       
   163         iCoeEnv.FsSession() );
       
   164     cleanupItems += 2;
       
   165 		
       
   166     if ( !ValidateAttachmentsL( attachments ) )
       
   167         { // User canceled sending.
       
   168         
       
   169         // Cleanup: attachments, *attachments
       
   170         CleanupStack::PopAndDestroy( cleanupItems );
       
   171         return;
       
   172         }
       
   173 
       
   174     const CRichText* bodyText = aMessageData->BodyText();
       
   175     if ( bodyText->DocumentLength() > 0 )
       
   176         {
       
   177         CSendUiAttachment* atta = CSendUiAttachment::NewLC( *bodyText, iCoeEnv.FsSession() );
       
   178         attachments->AppendL( atta );
       
   179         CleanupStack::Pop( atta );
       
   180         }
       
   181     TInt attachmentCount = attachments->Count();
       
   182 
       
   183     // No valid attachments
       
   184     if ( attachmentCount <= 0 )
       
   185         {
       
   186         CleanupStack::PopAndDestroy( cleanupItems  ); // *attachmemts, attachments
       
   187         return;
       
   188         }
       
   189 
       
   190     // Ask users opinion about sending files in separate messages or canceling
       
   191     // the actual sending operation.
       
   192     if ( attachmentCount > 1 )
       
   193         {
       
   194         if ( !ShowConfirmationQueryL( R_MMS_DIRECT_UPLOAD_SEND_MESSAGES_QUERY,
       
   195             R_MMS_DIRECT_UPLOAD_SEND_MESSAGES, attachmentCount ) )
       
   196             {
       
   197             CleanupStack::PopAndDestroy( cleanupItems );
       
   198             return;
       
   199             }
       
   200         }
       
   201 
       
   202    // Get service name
       
   203     HBufC* serviceName = NULL;
       
   204     for ( i = 0; i < iServiceArray.Count(); i++)
       
   205         {
       
   206         if ( (*iServiceArray[i]).ServiceId() == aServiceUid)
       
   207             {
       
   208             serviceName = ((*iServiceArray[i]).ServiceName()).AllocLC();
       
   209             cleanupItems++;
       
   210             if ( serviceName->Length() == 0 )
       
   211                 {
       
   212                 User::Leave( KErrNotFound );
       
   213                 }
       
   214             }
       
   215         }
       
   216 
       
   217     // Get service address
       
   218     HBufC*  serviceAddress = NULL;
       
   219     for ( i = 0; i < iServiceArray.Count(); i++)
       
   220         {
       
   221         if ( (*iServiceArray[i]).ServiceId() == aServiceUid)
       
   222             {
       
   223             serviceAddress = (*iServiceArray[i]).ServiceAddress().AllocLC();
       
   224             cleanupItems++;
       
   225             if ( serviceAddress->Length() == 0 )
       
   226                 {
       
   227                 User::Leave( KErrNotFound );
       
   228                 }
       
   229             }
       
   230         }
       
   231 
       
   232     // Create and send messages        
       
   233     CMDUSyncCreateAndSend* messageSender = CMDUSyncCreateAndSend::NewLC( iCoeEnv, iSingleton );
       
   234     cleanupItems++;
       
   235     
       
   236     TRAPD( error, messageSender->CreateAndSendL(
       
   237         attachments,
       
   238         *serviceAddress,
       
   239         *serviceName,
       
   240         iMaxMsgSize ) );
       
   241     // KErrCompletion is received, if for some attachments information note was shown
       
   242     if ( !( error == KErrNone || error == KErrCompletion ))
       
   243         {
       
   244         ErrorHandlerL( error, attachmentCount );
       
   245         }
       
   246 
       
   247     if( messageSender->Error() )
       
   248         {
       
   249         ErrorHandlerL( messageSender->Error(), attachmentCount );
       
   250         }
       
   251     else
       
   252         {
       
   253         // Get compression results
       
   254         TInt compressionOk = 0;
       
   255         TInt compressionFail = 0;
       
   256         
       
   257         messageSender->CompressionResults( compressionOk, compressionFail );
       
   258         
       
   259         if ( compressionFail > 0 )
       
   260             {
       
   261             ResolveCompressionQueryL(
       
   262                 attachmentCount, compressionFail );
       
   263             }
       
   264         }
       
   265     // Cleanup: serviceName, serviceAddress, messageSender, attachments, *attachments
       
   266     CleanupStack::PopAndDestroy( cleanupItems );
       
   267     }
       
   268 
       
   269 // -----------------------------------------------------------------------------
       
   270 // CMmsDirectUpload::ValidateAttachmentsL
       
   271 // Validates attachments for sending. DRM protection and MMS validity are
       
   272 // checked. DRM query and error note is shown if needed. Return value of
       
   273 // attachment arrays contains valid attachments. EFalse is returned if user
       
   274 // cancels sending, otherwise ETrue is returned.
       
   275 // (other items were commented in a header).
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 TBool CMmsDirectUpload::ValidateAttachmentsL(
       
   279     CArrayPtrFlat<CSendUiAttachment>* aAttachments )
       
   280     {
       
   281     TBool continueSending = ETrue;
       
   282    
       
   283     // Validate attachments and show query and error note if needed.
       
   284     if ( aAttachments->Count() > 0 )
       
   285         {
       
   286         CSendUiFileRightsEngine* fileRightsEngine =
       
   287             CSendUiFileRightsEngine::NewLC( iCoeEnv.FsSession() );
       
   288 
       
   289         fileRightsEngine->ConfirmDrmFileRightsL( aAttachments );
       
   290         fileRightsEngine->ConfirmMmsValidityL( aAttachments, KMmsDirectUpload );
       
   291 
       
   292         continueSending =
       
   293             fileRightsEngine->ShowDrmAndMmsInfoL( KMmsDirectUpload );
       
   294 
       
   295         CleanupStack::PopAndDestroy( fileRightsEngine );
       
   296         }
       
   297 
       
   298     return continueSending;
       
   299     }
       
   300 
       
   301 // -----------------------------------------------------------------------------
       
   302 // CMmsDirectUpload::ReadServiceDataL
       
   303 // Reads service names from resource file and addresses from shared data or 
       
   304 // from central repository.
       
   305 // (other items were commented in a header).
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 void CMmsDirectUpload::ReadServiceDataL()
       
   309     {
       
   310     // Read the maximum MMS message size (bytes).
       
   311     CRepository* mmsRepository = CRepository::NewL( KCRUidMmsEngine );
       
   312     mmsRepository->Get( KMmsEngineMaximumSendSize, iMaxMsgSize );
       
   313     delete mmsRepository;
       
   314 
       
   315     CRepository* senduiRepository = CRepository::NewLC( KCRUidSendUi );
       
   316     TInt i = 0;
       
   317     // Go through services and get settings for direct upload services.
       
   318     // There can be 0-4 direct upload services configured.
       
   319     for ( i = 0; i < KMmsUploadServiceCount; i++)
       
   320         {
       
   321         TInt serviceType = 0;
       
   322         TInt err = senduiRepository->Get( KSUMmsUploadType1 + i , serviceType );
       
   323         
       
   324         // Get settings and store those to service array.
       
   325         if ( !err && serviceType == KMmsDirectUploadService )
       
   326             {
       
   327             CSendingServiceInfo* serviceInfo = CSendingServiceInfo::NewL();
       
   328             CleanupStack::PushL( serviceInfo );
       
   329 
       
   330             HBufC* serviceAddress = HBufC::NewLC( KMaxServiceAddressLength );
       
   331             TPtr serviceAddressPtr = serviceAddress->Des();
       
   332             User::LeaveIfError( senduiRepository->Get( KSUMmsUploadAddress1 + i , serviceAddressPtr ) );
       
   333             serviceInfo->SetServiceAddressL( serviceAddressPtr );
       
   334             CleanupStack::PopAndDestroy( serviceAddress );
       
   335 
       
   336             HBufC* serviceName = HBufC::NewLC( KMaxServiceNameLength );
       
   337             TPtr serviceNamePtr = serviceName->Des();
       
   338             User::LeaveIfError( senduiRepository->Get( KSUMmsUploadServiceName1 + i , serviceNamePtr ) );
       
   339             serviceInfo->SetServiceNameL( serviceNamePtr );
       
   340             CleanupStack::PopAndDestroy( serviceName );
       
   341             
       
   342             HBufC* serviceMenuName = HBufC::NewLC( KMaxServiceMenuNameLength );
       
   343             TPtr serviceMenuNamePtr = serviceMenuName->Des();
       
   344             User::LeaveIfError( senduiRepository->Get( KSUMmsUploadServiceMenuName1 + i , serviceMenuNamePtr ) );
       
   345             serviceInfo->SetServiceMenuNameL( serviceMenuNamePtr );
       
   346             CleanupStack::PopAndDestroy( serviceMenuName );
       
   347 
       
   348             // Set service type.
       
   349             serviceInfo->SetServiceProviderId( KMmsDirectUpload );
       
   350             serviceInfo->SetServiceFeatures( CSendingServiceInfo::EServiceCanSendDirectly );
       
   351 
       
   352             // Set sending capabilities.
       
   353             TSendingCapabilities capabilities = 
       
   354                 TSendingCapabilities( 0, KMaxTInt,
       
   355                     TSendingCapabilities::ESupportsAttachments );
       
   356 
       
   357             serviceInfo->SetServiceCapabilities( capabilities );
       
   358 
       
   359             TUid serviceId = KNullUid;
       
   360             switch ( i )
       
   361                 {
       
   362                 case 0:
       
   363                     {
       
   364                     serviceId = KMmsUploadService1Id;
       
   365                     break;
       
   366                     }
       
   367                 case 1:
       
   368                     {
       
   369                     serviceId = KMmsUploadService2Id;
       
   370                     break;
       
   371                     }
       
   372                 case 2:
       
   373                     {
       
   374                     serviceId = KMmsUploadService3Id;
       
   375                     break;
       
   376                     }
       
   377                 case 3:
       
   378                     {
       
   379                     serviceId = KMmsUploadService4Id;
       
   380                     break;
       
   381                     }
       
   382                 default:
       
   383                     break;
       
   384                 }
       
   385             serviceInfo->SetServiceId( serviceId );
       
   386 
       
   387             iServiceArray.Append( serviceInfo );
       
   388             CleanupStack::Pop( serviceInfo );
       
   389             }
       
   390         }
       
   391 
       
   392     CleanupStack::PopAndDestroy( senduiRepository );
       
   393     }
       
   394 
       
   395 // ---------------------------------------------------------
       
   396 // CMmsDirectUpload::ShowConfirmationQueryL
       
   397 // Shows confirmation query.
       
   398 // (other items were commented in a header).
       
   399 // ---------------------------------------------------------
       
   400 //
       
   401 TBool CMmsDirectUpload::ShowConfirmationQueryL(
       
   402     const TUint&    aQueryId,
       
   403     const TUint&    aQueryTextId,
       
   404     TInt            aQueryValue) const
       
   405     {
       
   406     HBufC* prompt = NULL;
       
   407 
       
   408     // Get text to be shown
       
   409     if ( aQueryValue )
       
   410         {
       
   411         prompt = StringLoader::LoadLC( aQueryTextId, aQueryValue );
       
   412         }
       
   413     else
       
   414         {
       
   415         prompt = StringLoader::LoadLC( aQueryTextId );
       
   416         }
       
   417 
       
   418     // Create dialog
       
   419     CAknQueryDialog* dlg = CAknQueryDialog::NewL( CAknQueryDialog::ENoTone );
       
   420 
       
   421     TInt result = dlg->ExecuteLD( aQueryId, prompt->Des() );
       
   422 
       
   423     CleanupStack::PopAndDestroy( prompt ); // prompt
       
   424 
       
   425     return ( result == EAknSoftkeyOk );
       
   426     }
       
   427 
       
   428 // ---------------------------------------------------------
       
   429 // CMmsDirectUpload::ErrorHandlerL
       
   430 // Show confirmation query to the user if images have been compressed.
       
   431 // (other items were commented in a header).
       
   432 // ---------------------------------------------------------
       
   433 //
       
   434 void CMmsDirectUpload::ErrorHandlerL( TInt aErr, TInt aFileCount ) const
       
   435     {
       
   436     if ( aErr )
       
   437         {
       
   438         switch ( aErr )
       
   439             {
       
   440             case KMmsErrorInvalidSettings:
       
   441             case KMmsErrorNoWAPAccessPoint:
       
   442             case KMmsErrorNoWapAp1:
       
   443                 {
       
   444                 ShowErrorNoteL( aFileCount > 1 ?
       
   445                     R_SENDUI_SETTINGS_NOT_OK_MANY : R_SENDUI_SETTINGS_NOT_OK );
       
   446                 break;
       
   447                 }
       
   448             default:
       
   449                 {
       
   450                 ShowConfirmationQueryL( R_MMS_DIRECT_UPLOAD_CONFIRMABLE_INFO,
       
   451                     aFileCount > 1 ? 
       
   452                     R_MMS_DIRECT_UPLOAD_CREATION_FAILED_ALL:
       
   453                     R_MMS_DIRECT_UPLOAD_CREATION_FAILED_ONE);         
       
   454                 break;
       
   455                 }
       
   456             }
       
   457         }
       
   458     }
       
   459 
       
   460 // ---------------------------------------------------------
       
   461 // CMmsDirectUpload::ResolveCompressionQueryL
       
   462 // Show confirmation query to the user if images have been compressed.
       
   463 // (other items were commented in a header).
       
   464 // ---------------------------------------------------------
       
   465 //
       
   466 void CMmsDirectUpload::ResolveCompressionQueryL(
       
   467     TInt aFileCount,
       
   468     TInt aCompressionFail ) const
       
   469     {
       
   470     // Show confirmation query to the user if images have been compressed.
       
   471     if ( aCompressionFail > 0 )
       
   472         {
       
   473         // Compression has failed for all files
       
   474         if ( aFileCount == aCompressionFail )
       
   475             {
       
   476             ShowConfirmationQueryL( R_MMS_DIRECT_UPLOAD_CONFIRMABLE_INFO,
       
   477                 aCompressionFail > 1 ? 
       
   478                     R_MMS_DIRECT_UPLOAD_CREATION_FAILED_ALL:
       
   479                     R_MMS_DIRECT_UPLOAD_CREATION_FAILED_ONE);
       
   480             }
       
   481         else
       
   482             {
       
   483             ShowConfirmationQueryL( R_MMS_DIRECT_UPLOAD_CONFIRMABLE_INFO,
       
   484                 R_MMS_DIRECT_UPLOAD_CREATION_FAILED_SOME );
       
   485             }
       
   486         }
       
   487     }
       
   488 
       
   489 // ---------------------------------------------------------
       
   490 // CMmsDirectUpload::ShowErrorNoteL
       
   491 // Show error note to the user.
       
   492 // (other items were commented in a header).
       
   493 // ---------------------------------------------------------
       
   494 //   
       
   495 void CMmsDirectUpload::ShowErrorNoteL( TInt aResourceId ) const
       
   496     {
       
   497     HBufC* text = static_cast<CEikonEnv&>( iCoeEnv ).AllocReadResourceLC( aResourceId );
       
   498 
       
   499     CAknErrorNote* note = new (ELeave) CAknErrorNote;
       
   500     note->ExecuteLD(*text);
       
   501 
       
   502     CleanupStack::PopAndDestroy( text ); // text
       
   503     }
       
   504     
       
   505 TUid CMmsDirectUpload::TechnologyTypeId( ) const
       
   506 {
       
   507     return TUid::Uid( KSenduiTechnologyMmsUidValue );
       
   508 }
       
   509 
       
   510 //  End of File