emailuis/emailui/src/ncscomposeview.cpp
branchRCL_3
changeset 34 cd2816114bd1
parent 33 da5135c61bad
child 19 b13141f05c3d
equal deleted inserted replaced
33:da5135c61bad 34:cd2816114bd1
    82     CFSMailClient& aMailClient, CMsvSession& aMsvSession )
    82     CFSMailClient& aMailClient, CMsvSession& aMsvSession )
    83     : CFsEmailUiViewBase( aSendAttachmentControlGroup, aAppUi ),
    83     : CFsEmailUiViewBase( aSendAttachmentControlGroup, aAppUi ),
    84      iMailClient( aMailClient ), iOrigMessage( NULL ), iNewMessage( NULL ),
    84      iMailClient( aMailClient ), iOrigMessage( NULL ), iNewMessage( NULL ),
    85      iMsvSession( aMsvSession ), iEnv( aEnv ),
    85      iMsvSession( aMsvSession ), iEnv( aEnv ),
    86      iFakeSyncGoingOn(EFalse), iFetchDialogCancelled(EFalse),
    86      iFakeSyncGoingOn(EFalse), iFetchDialogCancelled(EFalse),
    87      iExecutingDoExitL( EFalse )
    87      iExecutingDoExitL( EFalse ),
       
    88      iMessageTextPartModified( EFalse ), iMessageModified( EFalse )
    88     {
    89     {
    89     FUNC_LOG;
    90     FUNC_LOG;
    90 
    91 
    91     iAttachmentListSaveDraft = EFalse;
    92     iAttachmentListSaveDraft = EFalse;
    92 
    93 
  1005             case ENcsCmdPriorityHigh:
  1006             case ENcsCmdPriorityHigh:
  1006             	{
  1007             	{
  1007             	iNewMessage->ResetFlag( EFSMsgFlag_Low );
  1008             	iNewMessage->ResetFlag( EFSMsgFlag_Low );
  1008             	iNewMessage->SetFlag( EFSMsgFlag_Important );
  1009             	iNewMessage->SetFlag( EFSMsgFlag_Important );
  1009             	iNewMessage->SaveMessageL();
  1010             	iNewMessage->SaveMessageL();
       
  1011                 iMessageModified = EFalse;
  1010             	iStatusPaneIndicators->SetPriorityFlag( EMsgPriorityHigh );
  1012             	iStatusPaneIndicators->SetPriorityFlag( EMsgPriorityHigh );
  1011             	}
  1013             	}
  1012                 break;
  1014                 break;
  1013         	case ENcsCmdPriorityNormal:
  1015         	case ENcsCmdPriorityNormal:
  1014     	    	{
  1016     	    	{
  1015             	iNewMessage->ResetFlag( EFSMsgFlag_Low );
  1017             	iNewMessage->ResetFlag( EFSMsgFlag_Low );
  1016             	iNewMessage->ResetFlag( EFSMsgFlag_Important );
  1018             	iNewMessage->ResetFlag( EFSMsgFlag_Important );
  1017             	iNewMessage->SaveMessageL();
  1019             	iNewMessage->SaveMessageL();
       
  1020                 iMessageModified = EFalse;
  1018             	iStatusPaneIndicators->SetPriorityFlag( EMsgPriorityNormal );
  1021             	iStatusPaneIndicators->SetPriorityFlag( EMsgPriorityNormal );
  1019     	    	}
  1022     	    	}
  1020                 break;
  1023                 break;
  1021         	case ENcsCmdPriorityLow:
  1024         	case ENcsCmdPriorityLow:
  1022     	    	{
  1025     	    	{
  1023             	iNewMessage->ResetFlag( EFSMsgFlag_Important );
  1026             	iNewMessage->ResetFlag( EFSMsgFlag_Important );
  1024             	iNewMessage->SetFlag( EFSMsgFlag_Low );
  1027             	iNewMessage->SetFlag( EFSMsgFlag_Low );
  1025             	iNewMessage->SaveMessageL();
  1028             	iNewMessage->SaveMessageL();
       
  1029                 iMessageModified = EFalse;
  1026             	iStatusPaneIndicators->SetPriorityFlag( EMsgPriorityLow );
  1030             	iStatusPaneIndicators->SetPriorityFlag( EMsgPriorityLow );
  1027     	    	}
  1031     	    	}
  1028                 break;
  1032                 break;
  1029             case ENcsCmdShowCc:
  1033             case ENcsCmdShowCc:
  1030                 {
  1034                 {
  1143     if ( iContainer->AreAddressFieldsEmpty() )
  1147     if ( iContainer->AreAddressFieldsEmpty() )
  1144         {
  1148         {
  1145         User::Leave( KErrNotFound );
  1149         User::Leave( KErrNotFound );
  1146         }
  1150         }
  1147 
  1151 
  1148 	CommitL();
  1152     CommitL( ETrue, EAllFields, ETrue );
  1149 
  1153 
  1150     TRAPD(r, iMailBox->SendMessageL( *iNewMessage ) );
  1154     TRAPD(r, iMailBox->SendMessageL( *iNewMessage ) );
  1151     if ( KErrNone != r )
  1155     if ( KErrNone != r )
  1152         {
  1156         {
  1153         iMailSendFailed = ETrue;
  1157         iMailSendFailed = ETrue;
  1192 
  1196 
  1193     	HBufC* saveItem = StringLoader::LoadLC( R_NCS_DRAFT_SAVE );
  1197     	HBufC* saveItem = StringLoader::LoadLC( R_NCS_DRAFT_SAVE );
  1194         array->AppendL( *saveItem );
  1198         array->AppendL( *saveItem );
  1195 		CleanupStack::PopAndDestroy( saveItem );
  1199 		CleanupStack::PopAndDestroy( saveItem );
  1196 
  1200 
  1197     	HBufC* deleteItem = StringLoader::LoadLC( R_NCS_DRAFT_DELETE );
  1201     	HBufC* deleteItem = StringLoader::LoadLC( R_NCS_DRAFT_DISCARD );
  1198         array->AppendL( *deleteItem );
  1202         array->AppendL( *deleteItem );
  1199 		CleanupStack::PopAndDestroy( deleteItem );
  1203 		CleanupStack::PopAndDestroy( deleteItem );
  1200 
  1204 
  1201 		iDlg = new (ELeave) CAknListQueryDialog( &selectedOption );
  1205 		iDlg = new (ELeave) CAknListQueryDialog( &selectedOption );
  1202     	iDlg->PrepareLC( R_DRAFT_QUERY_DIALOG );
  1206     	iDlg->PrepareLC( R_DRAFT_QUERY_DIALOG );
  1337 
  1341 
  1338     // get pointer to attachment list view
  1342     // get pointer to attachment list view
  1339 	CFreestyleEmailUiSendAttachmentsListControl* attachmentControl;
  1343 	CFreestyleEmailUiSendAttachmentsListControl* attachmentControl;
  1340 	attachmentControl = self->AttachmentsListControl();
  1344 	attachmentControl = self->AttachmentsListControl();
  1341 
  1345 
  1342    	// show file dialog and get file name
  1346     // show file dialog and get file name
  1343 	TBool ok = EFalse;
  1347     TBool ok = EFalse;
  1344 	TRAPD( error, ok = attachmentControl->AppendAttachmentToListL(
  1348     TInt error = KErrNone;
       
  1349     if( ! self->Toolbar()->IsDimmed())
       
  1350         {
       
  1351 	self->Toolbar()->SetDimmed(ETrue); 
       
  1352 	}
       
  1353 	
       
  1354     self->iContainer->SwitchChangeMskOff( ETrue );
       
  1355 	TRAP( error, ok = attachmentControl->AppendAttachmentToListL(
  1345                 self->iAttachmentAddType) );
  1356                 self->iAttachmentAddType) );
       
  1357     self->iContainer->SwitchChangeMskOff( EFalse );
       
  1358     
  1346 	if ( ok && error == KErrNone )
  1359 	if ( ok && error == KErrNone )
  1347 	    {
  1360 	    {
  1348 	    TRAPD( error, self->SetAttachmentLabelContentL() );
  1361 	    TRAP( error, self->SetAttachmentLabelContentL() );
  1349 	    return error;
  1362             }
       
  1363   	
       
  1364 	if(! attachmentControl->IsAttachmentAddingLocked())
       
  1365 	    {
       
  1366 	    self->Toolbar()->SetDimmed(EFalse); 
       
  1367 	    TRAP( error, self->UpdateToolbarL());
  1350 	    }
  1368 	    }
  1351 	return error;
  1369 	return error;
  1352     }
  1370     }
  1353 
  1371 
  1354 // -----------------------------------------------------------------------------
  1372 // -----------------------------------------------------------------------------
  1519         if ( iNewMessage->GetContentType() != 
  1537         if ( iNewMessage->GetContentType() != 
  1520              KFSMailContentTypeMultipartMixed )
  1538              KFSMailContentTypeMultipartMixed )
  1521             {
  1539             {
  1522             iNewMessage->SetContentType( KFSMailContentTypeMultipartMixed );
  1540             iNewMessage->SetContentType( KFSMailContentTypeMultipartMixed );
  1523             iNewMessage->SaveMessageL();
  1541             iNewMessage->SaveMessageL();
       
  1542             iMessageModified = EFalse;
  1524             }
  1543             }
  1525         
  1544         
  1526         TFsEmailUiUtility::CreatePlainTextPartL( 
  1545         TFsEmailUiUtility::CreatePlainTextPartL( 
  1527                 *iNewMessage, iNewMessageTextPart );
  1546                 *iNewMessage, iNewMessageTextPart );
  1528         IncludeMessageTextL( ETrue );
  1547         IncludeMessageTextL( ETrue );
  1596             }
  1615             }
  1597 
  1616 
  1598         iOrigMessage = NULL;
  1617         iOrigMessage = NULL;
  1599         iNewMessage->SetContentType( KFSMailContentTypeMultipartMixed );
  1618         iNewMessage->SetContentType( KFSMailContentTypeMultipartMixed );
  1600         iNewMessage->SaveMessageL();
  1619         iNewMessage->SaveMessageL();
       
  1620         iMessageModified = EFalse;
  1601         TFsEmailUiUtility::CreatePlainTextPartL( 
  1621         TFsEmailUiUtility::CreatePlainTextPartL( 
  1602                 *iNewMessage, iNewMessageTextPart );
  1622                 *iNewMessage, iNewMessageTextPart );
  1603         InitFieldsL();
  1623         InitFieldsL();
  1604         IncludeMessageTextL();
  1624         IncludeMessageTextL();
  1605         AttachmentsListControl()->Model()->Clear();
  1625         AttachmentsListControl()->Model()->Clear();
  1625             {
  1645             {
  1626             User::Leave( KErrGeneral );
  1646             User::Leave( KErrGeneral );
  1627             }
  1647             }
  1628         iNewMessage->SetContentType( KFSMailContentTypeMultipartMixed );
  1648         iNewMessage->SetContentType( KFSMailContentTypeMultipartMixed );
  1629         iNewMessage->SaveMessageL();
  1649         iNewMessage->SaveMessageL();
       
  1650         iMessageModified = EFalse;
  1630 
  1651 
  1631         TFsEmailUiUtility::CreatePlainTextPartL( 
  1652         TFsEmailUiUtility::CreatePlainTextPartL( 
  1632                 *iNewMessage, iNewMessageTextPart );
  1653                 *iNewMessage, iNewMessageTextPart );
  1633 
  1654 
  1634         IncludeMessageTextL( ETrue );
  1655         IncludeMessageTextL( ETrue );
  1998 // -----------------------------------------------------------------------------
  2019 // -----------------------------------------------------------------------------
  1999 // CNcsComposeView::CommitL()
  2020 // CNcsComposeView::CommitL()
  2000 //
  2021 //
  2001 // -----------------------------------------------------------------------------
  2022 // -----------------------------------------------------------------------------
  2002 //
  2023 //
  2003 void CNcsComposeView::CommitL( 
  2024 void CNcsComposeView::CommitL( TBool aParseAddresses,
  2004         TBool aParseAddresses, TFieldToCommit aFieldToCommit )
  2025     TFieldToCommit aFieldToCommit, TBool aSaveNow )
  2005     {
  2026     {
  2006     FUNC_LOG;
  2027     FUNC_LOG;
  2007     __ASSERT_DEBUG( iNewMessage, Panic( ENcsBasicUi ) );
  2028     __ASSERT_DEBUG( iNewMessage, Panic( ENcsBasicUi ) );
  2008 	__ASSERT_DEBUG( iNewMessageTextPart, Panic( ENcsBasicUi ) );
  2029 	__ASSERT_DEBUG( iNewMessageTextPart, Panic( ENcsBasicUi ) );
  2009 
  2030 
  2035             commitBodyField = ETrue;
  2056             commitBodyField = ETrue;
  2036             break;
  2057             break;
  2037         case ESubjectField:
  2058         case ESubjectField:
  2038             commitSubjectField = ETrue;
  2059             commitSubjectField = ETrue;
  2039             break;
  2060             break;
  2040 	    default:
  2061         default:
  2041 	        break;
  2062             break;
  2042 	    }
  2063         }
  2043 
  2064 
  2044 	if ( commitToField )
  2065     if ( commitToField )
  2045 		{
  2066         {
  2046 	    // get addresses from UI to MSG object
  2067         RPointerArray<CFSMailAddress>& recipients = 
  2047 	    RPointerArray<CFSMailAddress> toAddresses;
  2068             iNewMessage->GetToRecipients();
  2048 	    CleanupResetAndDestroyClosePushL( toAddresses );
  2069         recipients.ResetAndDestroy();
  2049 	    NcsUtility::ConvertAddressArrayL( 
  2070         NcsUtility::ConvertAddressArrayL(
  2050 	            iContainer->GetToFieldAddressesL( aParseAddresses ), 
  2071             iContainer->GetToFieldAddressesL( aParseAddresses ), recipients );
  2051 	            toAddresses );
  2072         }
  2052 	    iNewMessage->GetToRecipients().ResetAndDestroy();
  2073 
  2053 	    for ( TInt i = 0 ; i < toAddresses.Count() ; i++ )
  2074     if ( commitCcField )
  2054 	    	{
  2075         {
  2055 	    	iNewMessage->AppendToRecipient( toAddresses[i] );
  2076         RPointerArray<CFSMailAddress>& recipients = 
  2056 	        // Ownership of the message pointer was transferred from our array
  2077             iNewMessage->GetCCRecipients();
  2057 	    	// to iNewMessage
  2078         recipients.ResetAndDestroy();
  2058 	        toAddresses[i] = NULL;
  2079         NcsUtility::ConvertAddressArrayL( 
  2059 	    	}
  2080             iContainer->GetCcFieldAddressesL( aParseAddresses ), recipients );
  2060 	    CleanupStack::PopAndDestroy( &toAddresses );
  2081         }
  2061 		}
  2082 
  2062 
  2083     if ( commitBccField )
  2063 	if ( commitCcField )
  2084         {
  2064 		{
  2085         RPointerArray<CFSMailAddress>& recipients = 
  2065 	    RPointerArray<CFSMailAddress> ccAddresses;
  2086             iNewMessage->GetBCCRecipients();
  2066 	    CleanupResetAndDestroyClosePushL( ccAddresses );
  2087         recipients.ResetAndDestroy();
  2067 	    NcsUtility::ConvertAddressArrayL( 
  2088         NcsUtility::ConvertAddressArrayL( 
  2068 	            iContainer->GetCcFieldAddressesL( aParseAddresses ), 
  2089             iContainer->GetBccFieldAddressesL( aParseAddresses ), recipients );
  2069 	            ccAddresses );
  2090         }
  2070 	    iNewMessage->GetCCRecipients().ResetAndDestroy();
       
  2071 	    for ( TInt i = 0 ; i < ccAddresses.Count() ; i++ )
       
  2072 	    	{
       
  2073 	    	iNewMessage->AppendCCRecipient( ccAddresses[i] );
       
  2074 	        // Ownership of the message pointer was transferred from 
       
  2075 	    	// our array to iNewMessage
       
  2076 	        ccAddresses[i] = NULL;
       
  2077 	    	}
       
  2078 	    CleanupStack::PopAndDestroy( &ccAddresses );
       
  2079 		}
       
  2080 
       
  2081 	if ( commitBccField )
       
  2082 		{
       
  2083 	    RPointerArray<CFSMailAddress> bccAddresses;
       
  2084 	    CleanupResetAndDestroyClosePushL( bccAddresses );
       
  2085 	    NcsUtility::ConvertAddressArrayL( 
       
  2086 	            iContainer->GetBccFieldAddressesL( aParseAddresses ), 
       
  2087 	            bccAddresses );
       
  2088 	    iNewMessage->GetBCCRecipients().ResetAndDestroy();
       
  2089 	    for ( TInt i = 0; i < bccAddresses.Count() ; i++ )
       
  2090 	    	{
       
  2091 	    	iNewMessage->AppendBCCRecipient( bccAddresses[i] );
       
  2092 	        // Ownership of the message pointer was transferred from 
       
  2093 	    	// our array to iNewMessage
       
  2094 	        bccAddresses[i] = NULL;
       
  2095 	    	}
       
  2096 	    CleanupStack::PopAndDestroy( &bccAddresses );
       
  2097 		}
       
  2098 
  2091 
  2099 	if ( commitSubjectField )
  2092 	if ( commitSubjectField )
  2100 	    {
  2093 	    {
  2101 	    // get subject from UI to MSG object
  2094 	    // get subject from UI to MSG object
  2102 	    HBufC* subject = iContainer->GetSubjectLC();
  2095 	    HBufC* subject = iContainer->GetSubjectLC();
  2114         HBufC* body = iContainer->GetBodyContentLC();
  2107         HBufC* body = iContainer->GetBodyContentLC();
  2115         TPtr bodyPtr = body->Des(); // this TPtr is needed only because of
  2108         TPtr bodyPtr = body->Des(); // this TPtr is needed only because of
  2116         // incorrect argument type in FW API, can be removed when API fixed
  2109         // incorrect argument type in FW API, can be removed when API fixed
  2117         iNewMessageTextPart->SetContent( bodyPtr );
  2110         iNewMessageTextPart->SetContent( bodyPtr );
  2118         CleanupStack::PopAndDestroy( body );
  2111         CleanupStack::PopAndDestroy( body );
  2119 
  2112         iMessageTextPartModified = ETrue;
  2120         TInt error = KErrNone;
  2113         }
  2121         if ( iNewMessageTextPart )
  2114 
  2122             {
  2115     iMessageModified = ETrue;
  2123             TRAP( error, iNewMessageTextPart->SaveL() );
  2116     RefreshToolbar();
  2124             }
  2117 
  2125         }
  2118     if ( aSaveNow )
  2126 
  2119         {
  2127 	// Save message if at least one field committed
  2120         SaveMessageL();
  2128     if ( iNewMessage || commitToField || commitCcField || commitBccField
  2121         }
  2129         || commitSubjectField || commitBodyField )
  2122     }
  2130         {
  2123 
  2131         TInt error = KErrNone;
  2124 TInt CNcsComposeView::SaveMessage()
  2132         if(iNewMessage) // Coverity error fix:
  2125     {
  2133             {
  2126     FUNC_LOG;
  2134             TRAP( error, iNewMessage->SaveMessageL() );
  2127     TInt error = KErrNone;
  2135             }
  2128     TRAP( error, SaveMessageL() );
  2136         RefreshToolbar();
  2129     return error;
       
  2130     }
       
  2131 
       
  2132 // -----------------------------------------------------------------------------
       
  2133 // Saves the new message if it has been modifed since the last save.
       
  2134 // -----------------------------------------------------------------------------
       
  2135 void CNcsComposeView::SaveMessageL()
       
  2136     {
       
  2137     FUNC_LOG;
       
  2138     if ( iNewMessageTextPart && iMessageTextPartModified )
       
  2139         {
       
  2140         iNewMessageTextPart->SaveL();
       
  2141         iMessageTextPartModified = EFalse;
       
  2142         }
       
  2143 
       
  2144     if ( iNewMessage && iMessageModified )
       
  2145         {
       
  2146         iNewMessage->SaveMessageL();
       
  2147         iMessageModified = EFalse;
  2137         }
  2148         }
  2138     }
  2149     }
  2139 
  2150 
  2140 // -----------------------------------------------------------------------------
  2151 // -----------------------------------------------------------------------------
  2141 // CNcsComposeView::DoSafeExit
  2152 // CNcsComposeView::DoSafeExit
  2142 // -----------------------------------------------------------------------------
  2153 // -----------------------------------------------------------------------------
  2143 void CNcsComposeView::DoSafeExit( TExitMode aMode )
  2154 void CNcsComposeView::DoSafeExit( TExitMode aMode )
  2144     {
  2155     {
  2145     FUNC_LOG;
  2156     FUNC_LOG;
  2146 
       
  2147     if ( !iExecutingDoExitL )
  2157     if ( !iExecutingDoExitL )
  2148         {
  2158         {
  2149         iExecutingDoExitL = ETrue;
  2159         iExecutingDoExitL = ETrue;
  2150         TRAP_IGNORE( DoExitL( aMode ) );
  2160         TRAP_IGNORE( DoExitL( aMode ) );
  2151         iExecutingDoExitL = EFalse;
  2161         iExecutingDoExitL = EFalse;
  2658 
  2668 
  2659     if ( iNewMessage->GetContentType() != KFSMailContentTypeMultipartMixed )
  2669     if ( iNewMessage->GetContentType() != KFSMailContentTypeMultipartMixed )
  2660         {
  2670         {
  2661         iNewMessage->SetContentType( KFSMailContentTypeMultipartMixed );
  2671         iNewMessage->SetContentType( KFSMailContentTypeMultipartMixed );
  2662         iNewMessage->SaveMessageL();
  2672         iNewMessage->SaveMessageL();
  2663 	    }
  2673         iMessageModified = EFalse;
  2664 	
  2674         }
  2665 	TFsEmailUiUtility::CreatePlainTextPartL( *iNewMessage, iNewMessageTextPart );
  2675 
  2666 
  2676     TFsEmailUiUtility::CreatePlainTextPartL( *iNewMessage, iNewMessageTextPart );
  2667 	}
  2677     }
  2668 
  2678 
  2669 // -----------------------------------------------------------------------------
  2679 // -----------------------------------------------------------------------------
  2670 // CNcsComposeView::GenerateForwardMessageL
  2680 // CNcsComposeView::GenerateForwardMessageL
  2671 // -----------------------------------------------------------------------------
  2681 // -----------------------------------------------------------------------------
  2672 //
  2682 //
  2860     {
  2870     {
  2861     FUNC_LOG;
  2871     FUNC_LOG;
  2862     if ( iFirstStartCompleted && iNewMessage && iMailBox 
  2872     if ( iFirstStartCompleted && iNewMessage && iMailBox 
  2863          && aActionCommand.Id() == KCmdEditorAutoSave )
  2873          && aActionCommand.Id() == KCmdEditorAutoSave )
  2864         {
  2874         {
  2865         CommitL( EFalse );
  2875         CommitL( EFalse, EAllFields, ETrue );
  2866         }
  2876         }
  2867     }
  2877     }
  2868 
  2878 
  2869 // -----------------------------------------------------------------------------
  2879 // -----------------------------------------------------------------------------
  2870 // CNcsComposeView::SaveToDraftsL
  2880 // CNcsComposeView::SaveToDraftsL
  2877         {
  2887         {
  2878         __ASSERT_DEBUG( iMailBox, Panic( ENcsBasicUi ) );
  2888         __ASSERT_DEBUG( iMailBox, Panic( ENcsBasicUi ) );
  2879         __ASSERT_DEBUG( iNewMessage, Panic( ENcsBasicUi ) );
  2889         __ASSERT_DEBUG( iNewMessage, Panic( ENcsBasicUi ) );
  2880 
  2890 
  2881         iFakeSyncGoingOn = ETrue;
  2891         iFakeSyncGoingOn = ETrue;
  2882         TRAPD( error, CommitL( aParseAddresses ) );
  2892         TRAPD( error, CommitL( aParseAddresses, EAllFields, ETrue ) );
  2883         iFakeSyncGoingOn = EFalse;
  2893         iFakeSyncGoingOn = EFalse;
  2884         User::LeaveIfError( error );
  2894         User::LeaveIfError( error );
  2885 
  2895 
  2886         iFakeSyncGoingOn = ETrue;
  2896         iFakeSyncGoingOn = ETrue;
  2887         TRAP( error, TFsEmailUiUtility::MoveMessageToDraftsL(
  2897         TRAP( error, TFsEmailUiUtility::MoveMessageToDraftsL(