|
1 /* |
|
2 * Copyright (c) 2002 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: Static helper methods. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "MailUtils.h" // Own header |
|
21 #include <MsgMailUtils.rsg> |
|
22 |
|
23 #include <AknQueryDialog.h> // CAknTextQueryDialog |
|
24 #include <aknnotewrappers.h> |
|
25 #include <StringLoader.h> // StringLoader |
|
26 #include <MuiuMsvUiServiceUtilities.h> |
|
27 #include <CommonContentPolicy.h> |
|
28 #include <e32property.h> |
|
29 #include <coemain.h> |
|
30 #include <CoreApplicationUIsSDKCRKeys.h> |
|
31 |
|
32 // This is a maximum size in KBs for attachments which are |
|
33 // fetched without confirmation query |
|
34 const TInt KMaximumAttachmentSize(100); |
|
35 |
|
36 // ================= MEMBER FUNCTIONS ======================= |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // MailUtils::TextQueryL |
|
40 // leaves if user cancels query |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 EXPORT_C void MailUtils::TextQueryL(TInt aQueryResource, TDes& aText) |
|
44 { |
|
45 CAknTextQueryDialog* dlg = new (ELeave) CAknTextQueryDialog(aText,CAknQueryDialog::ENoTone); |
|
46 if (dlg->ExecuteLD(aQueryResource)) //R_DATA_QUERY |
|
47 { |
|
48 // query approved |
|
49 return; |
|
50 } |
|
51 // query was cancelled |
|
52 User::Leave(KLeaveWithoutAlert); |
|
53 } |
|
54 // ----------------------------------------------------------------------------- |
|
55 // MailUtils::ConfirmationNoteL |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 EXPORT_C void MailUtils::ConfirmationNoteL(const TDesC& aText) |
|
59 { |
|
60 CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote; |
|
61 note->ExecuteLD(aText); |
|
62 } |
|
63 // ----------------------------------------------------------------------------- |
|
64 // MailUtils::ConfirmationNoteL |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 EXPORT_C void MailUtils::ConfirmationNoteL(TInt aStringResource) |
|
68 { |
|
69 HBufC* buf = StringLoader::LoadLC(aStringResource); |
|
70 ConfirmationNoteL(*buf); |
|
71 CleanupStack::PopAndDestroy(buf); |
|
72 } |
|
73 // ----------------------------------------------------------------------------- |
|
74 // MailUtils::InformationNoteL |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 EXPORT_C void MailUtils::InformationNoteL(const TDesC& aText) |
|
78 { |
|
79 CAknInformationNote* note = new (ELeave) CAknInformationNote(ETrue); |
|
80 note->ExecuteLD(aText); |
|
81 } |
|
82 // ----------------------------------------------------------------------------- |
|
83 // MailUtils::InformationNoteL |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 EXPORT_C void MailUtils::InformationNoteL(TInt aStringResource) |
|
87 { |
|
88 HBufC* buf = StringLoader::LoadLC(aStringResource); |
|
89 InformationNoteL(*buf); |
|
90 CleanupStack::PopAndDestroy(buf); |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // MailUtils::ShowNoteIfMsgStoreSpaceLowL |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 EXPORT_C TBool MailUtils::ShowNoteIfMsgStoreSpaceLowL(const TInt /*aSize*/) |
|
98 { |
|
99 // Deprecated -> to be removed |
|
100 User::Leave(KErrNotSupported); |
|
101 |
|
102 return EFalse; |
|
103 } |
|
104 // ----------------------------------------------------------------------------- |
|
105 // MailUtils::OfflineProfileActiveL |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 EXPORT_C TBool MailUtils::OfflineProfileActiveL() |
|
109 { |
|
110 TInt value(0); |
|
111 TBool retVal(EFalse); |
|
112 |
|
113 CRepository* cenRep = CRepository::NewLC( KCRUidCoreApplicationUIs ); |
|
114 TInt err = cenRep->Get(KCoreAppUIsNetworkConnectionAllowed, value ); |
|
115 if ( !err && !value ) |
|
116 { // Phone is offline |
|
117 retVal = ETrue; |
|
118 } |
|
119 CleanupStack::PopAndDestroy(); // cenRep |
|
120 return retVal; |
|
121 } |
|
122 // ----------------------------------------------------------------------------- |
|
123 // MailUtils::IsClosedMimeL |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 EXPORT_C TBool MailUtils::IsClosedMimeL(const TDesC& aMimeType) |
|
127 { |
|
128 CCommonContentPolicy* contentPolicy = CCommonContentPolicy::NewLC(); |
|
129 |
|
130 TBool banned(contentPolicy->IsClosedType( aMimeType )); |
|
131 |
|
132 CleanupStack::PopAndDestroy(); //contentPolicy |
|
133 |
|
134 return banned; |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // MailUtils::IsClosedMimeL |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 EXPORT_C TBool MailUtils::IsClosedMimeL(const TDesC8& aMimeType) |
|
142 { |
|
143 HBufC* dataTypeString = HBufC::NewLC(aMimeType.Length()); |
|
144 dataTypeString->Des().Copy(aMimeType); |
|
145 TBool banned(ETrue); |
|
146 |
|
147 banned = IsClosedMimeL(*dataTypeString); |
|
148 |
|
149 CleanupStack::PopAndDestroy(); //contentPolicy |
|
150 |
|
151 return banned; |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // MailUtils::IsClosedFileL |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 EXPORT_C TBool MailUtils::IsClosedFileL( RFile& aFileHandle ) |
|
159 { |
|
160 if ( aFileHandle.SubSessionHandle() != 0 ) |
|
161 { |
|
162 CCommonContentPolicy* contentPolicy = CCommonContentPolicy::NewLC(); |
|
163 |
|
164 TBool banned( contentPolicy->IsClosedFileL( aFileHandle ) ); |
|
165 |
|
166 CleanupStack::PopAndDestroy(); //contentPolicy |
|
167 return banned; |
|
168 } |
|
169 else |
|
170 { |
|
171 return EFalse; |
|
172 } |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // MailUtils::ConfirmationQueryL |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 EXPORT_C TBool MailUtils::ConfirmationQueryL(const TDesC& aText, TInt aNoteResource) |
|
180 { |
|
181 CAknQueryDialog* qDlg = CAknQueryDialog::NewL(); |
|
182 |
|
183 if (qDlg->ExecuteLD(aNoteResource, aText)) |
|
184 { |
|
185 return ETrue; |
|
186 } |
|
187 return EFalse; |
|
188 } |
|
189 |
|
190 // ----------------------------------------------------------------------------- |
|
191 // MailUtils::ConfirmationQueryL |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 EXPORT_C TBool MailUtils::ConfirmationQueryL( |
|
195 TInt aStringResource, |
|
196 TInt aNoteResource) |
|
197 { |
|
198 HBufC* buf = StringLoader::LoadLC(aStringResource); |
|
199 TBool result = ConfirmationQueryL(*buf, aNoteResource); |
|
200 CleanupStack::PopAndDestroy(buf); |
|
201 return result; |
|
202 } |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // MailUtils::LargeAttachmentQueryL |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 EXPORT_C TBool MailUtils::LargeAttachmentQueryL( TInt aSize, TInt aStatus ) |
|
209 { |
|
210 |
|
211 TInt size( aSize / KKilo ); |
|
212 // This check is done in MsgAttachmentUtils::FileSizeToStringL |
|
213 // so it is done here also, so consistent sizes are shown to user. |
|
214 if (size % KKilo) |
|
215 { |
|
216 size++; |
|
217 } |
|
218 enum TResponce |
|
219 { |
|
220 EMsgMailNotQueried, |
|
221 EMsgMailFetch, |
|
222 EMsgMailDontFetch |
|
223 }; |
|
224 TInt noteResource( R_MAIL_QUEST_LARGE_ATTA_FWD ); |
|
225 TInt secondNoteResource( R_MAIL_QUEST_FETCH_ATTA_FWD ); |
|
226 if ( (aStatus & EQueryAttachmentFetch ) ) |
|
227 { |
|
228 noteResource = R_MAIL_LARGE_ATTA_QUERY; |
|
229 secondNoteResource = R_MAIL_QUEST_FETCH_ATTACHMENT; |
|
230 } |
|
231 |
|
232 TBool response( EMsgMailNotQueried ); |
|
233 |
|
234 if ( size > KMaximumAttachmentSize ) |
|
235 { |
|
236 HBufC* string = StringLoader::LoadLC( |
|
237 noteResource, |
|
238 size ); |
|
239 if ( !MailUtils::ConfirmationQueryL(*string, |
|
240 R_MAIL_YES_NO_QUERY_DLG) ) |
|
241 { |
|
242 response = EMsgMailDontFetch; |
|
243 } |
|
244 else |
|
245 { |
|
246 response = EMsgMailFetch; |
|
247 } |
|
248 CleanupStack::PopAndDestroy(); // string |
|
249 } |
|
250 |
|
251 if ( response == EMsgMailDontFetch ) |
|
252 { |
|
253 return EFalse; |
|
254 } |
|
255 |
|
256 // if we're offline, ask confirmation to connect |
|
257 if ( response == EMsgMailNotQueried && (aStatus & EConnectionOffline) ) |
|
258 { |
|
259 if ( !MailUtils::ConfirmationQueryL( |
|
260 secondNoteResource, |
|
261 R_MAIL_YES_NO_QUERY_DLG) ) |
|
262 { |
|
263 return EFalse; |
|
264 } |
|
265 } |
|
266 |
|
267 return ETrue; |
|
268 } |
|
269 // ----------------------------------------------------------------------------- |
|
270 // MailUtils::OfflineProfileActiveWithNoteL |
|
271 // ----------------------------------------------------------------------------- |
|
272 // |
|
273 EXPORT_C TBool MailUtils::OfflineProfileActiveWithNoteL() |
|
274 { |
|
275 User::Leave( KErrNotSupported ); |
|
276 return EFalse; |
|
277 } |
|
278 |
|
279 // ----------------------------------------------------------------------------- |
|
280 // MailUtils::ConfirmationQueryL |
|
281 // ----------------------------------------------------------------------------- |
|
282 // |
|
283 EXPORT_C TBool MailUtils::ConfirmationQueryL( const TDesC& aText ) |
|
284 { |
|
285 return MailUtils::ConfirmationQueryL( aText, R_MAIL_YES_NO_QUERY_DLG ); |
|
286 } |
|
287 |
|
288 // ----------------------------------------------------------------------------- |
|
289 // MailUtils::ConfirmationQueryL |
|
290 // ----------------------------------------------------------------------------- |
|
291 // |
|
292 EXPORT_C TBool MailUtils::ConfirmationQueryL( TInt aStringResource ) |
|
293 { |
|
294 return MailUtils::ConfirmationQueryL( |
|
295 aStringResource, R_MAIL_YES_NO_QUERY_DLG ); |
|
296 } |
|
297 |
|
298 // ----------------------------------------------------------------------------- |
|
299 // MailUtils::FileSize() |
|
300 // ----------------------------------------------------------------------------- |
|
301 // |
|
302 EXPORT_C TInt MailUtils::FileSize(const TDesC& aFilename) |
|
303 { |
|
304 RFile file; |
|
305 RFs& fs = CCoeEnv::Static()->FsSession(); |
|
306 TInt filesize(file.Open(fs, aFilename, EFileShareReadersOnly)); |
|
307 if (filesize == KErrNone) |
|
308 { |
|
309 file.Size(filesize); |
|
310 } |
|
311 file.Close(); |
|
312 |
|
313 return filesize; |
|
314 } |
|
315 |
|
316 // End of File |