|
1 /* |
|
2 * Copyright (c) 2004 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: Class for attachment verification |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "Msgattachmentverifier.h" |
|
21 #include "MsgMailDRMHandler.h" |
|
22 #include "MailUtils.h" |
|
23 #include <MsgMailEditor.rsg> |
|
24 #include <MuiuMsvUiServiceUtilities.h> |
|
25 #include <e32base.h> |
|
26 #include <coemain.h> |
|
27 |
|
28 // LOCAL CONSTANTS AND MACROS |
|
29 |
|
30 |
|
31 // ================= MEMBER FUNCTIONS ======================= |
|
32 |
|
33 // C++ default constructor cannot contain any code that might leave |
|
34 CMsgAttachmentVerifier::CMsgAttachmentVerifier( CMsvSession& aMsvSession ) |
|
35 : iMsvSession( aMsvSession ) |
|
36 { |
|
37 } |
|
38 // Symbian OS default constructor can leave. |
|
39 void CMsgAttachmentVerifier::ConstructL() |
|
40 { |
|
41 iDRMHandler = MsgMailDRMHandler::NewL(); |
|
42 } |
|
43 // NewLC |
|
44 CMsgAttachmentVerifier* CMsgAttachmentVerifier::NewLC( |
|
45 CMsvSession& aMsvSession ) |
|
46 { |
|
47 CMsgAttachmentVerifier* self = |
|
48 new (ELeave) CMsgAttachmentVerifier( aMsvSession ); |
|
49 CleanupStack::PushL(self); |
|
50 self->ConstructL(); |
|
51 return self; |
|
52 } |
|
53 |
|
54 |
|
55 // Destructor |
|
56 CMsgAttachmentVerifier::~CMsgAttachmentVerifier() |
|
57 { |
|
58 delete iDRMHandler; |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // Verify selected files or show a note if something wrong in a selection. |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 TBool CMsgAttachmentVerifier::VerifySelectionL( |
|
66 const MDesCArray* aSelectedFiles ) |
|
67 { |
|
68 ASSERT( aSelectedFiles ); |
|
69 TBool result( ETrue ); |
|
70 TInt attachmentsByteSize( 0 ); |
|
71 TInt selectionCount = aSelectedFiles->MdcaCount(); |
|
72 for (TInt i=0; i<selectionCount && result; i++) |
|
73 { |
|
74 TInt fileSize( 0 ); |
|
75 result = VerifyFileL( aSelectedFiles->MdcaPoint(i), fileSize ); |
|
76 attachmentsByteSize += fileSize; |
|
77 } |
|
78 if ( result ) |
|
79 { |
|
80 result = VerifyDiskSpaceL( attachmentsByteSize ); |
|
81 } |
|
82 return result; |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // Verify selected files or show a note if something wrong in a selection. |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 TBool CMsgAttachmentVerifier::OkToExitL( |
|
90 const TDesC& aDriveAndPath, const TEntry& aEntry ) |
|
91 { |
|
92 TBool result( ETrue ); |
|
93 TInt length = aDriveAndPath.Length() + aEntry.iName.Length(); |
|
94 if ( length ) |
|
95 { |
|
96 HBufC* filename = HBufC::NewLC( length ); |
|
97 TPtr ptr = filename->Des(); |
|
98 ptr.Append( aDriveAndPath ); |
|
99 ptr.Append( aEntry.iName ); |
|
100 TInt fileSize( 0 ); |
|
101 result = VerifyFileL( *filename, fileSize ); |
|
102 CleanupStack::PopAndDestroy( filename ); |
|
103 if ( result ) |
|
104 { |
|
105 result = VerifyDiskSpaceL( fileSize ); |
|
106 } |
|
107 } |
|
108 return result; |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // Verify selected files or show a note if something wrong in a selection. |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 TBool CMsgAttachmentVerifier::VerifyFileL( |
|
116 const TDesC& aFilename, |
|
117 TInt& aFileByteSize ) |
|
118 { |
|
119 RFs& fs = CCoeEnv::Static()->FsSession(); |
|
120 TBool result( ETrue ); |
|
121 RFile attachment; |
|
122 User::LeaveIfError( attachment.Open( |
|
123 fs, |
|
124 aFilename, |
|
125 EFileShareReadersOnly) ); |
|
126 |
|
127 CleanupClosePushL(attachment); |
|
128 |
|
129 // Size() may return error value but then we can just ignore it, file |
|
130 // size checking is not considered that necessary |
|
131 aFileByteSize = 0; |
|
132 attachment.Size( aFileByteSize ); |
|
133 |
|
134 if ( MailUtils::IsClosedFileL( attachment ) ) |
|
135 { |
|
136 MailUtils::InformationNoteL(R_QTN_MAIL_SEND_FORBID_1); |
|
137 result = EFalse; |
|
138 } |
|
139 else if ( iDRMHandler->IsSuperDistributableFileL( attachment ) ) |
|
140 { |
|
141 result = MailUtils::ConfirmationQueryL( |
|
142 R_QTN_MAIL_SEND_WO_RIGHTS_SD_1, |
|
143 R_MAIL_EDITOR_DELETE_MESSAGE ); |
|
144 } |
|
145 // attachment |
|
146 CleanupStack::PopAndDestroy(); // CSI: 12 # RFile |
|
147 return result; |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // Verifies that there is enough disk space to add attachment(s) |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 TBool CMsgAttachmentVerifier::VerifyDiskSpaceL( TInt aAttachmentsByteSize ) |
|
155 { |
|
156 TBool result( ETrue ); |
|
157 if ( MsvUiServiceUtilities::DiskSpaceBelowCriticalLevelL( |
|
158 iMsvSession, aAttachmentsByteSize ) ) |
|
159 { |
|
160 MailUtils::ConfirmationQueryL( R_QTN_MEMLO_NOT_ENOUGH_MEMORY, |
|
161 R_MAIL_CONFIRM_NOT_ENOUGH_MEMORY ); |
|
162 result = EFalse; |
|
163 } |
|
164 return result; |
|
165 } |
|
166 |
|
167 |
|
168 // End of File |