|
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: MsgAttachmentInfo implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // ========== INCLUDE FILES ================================ |
|
21 |
|
22 #include <eikenv.h> |
|
23 #include <gulicon.h> |
|
24 |
|
25 #include "MsgAttachmentInfo.h" |
|
26 #include "MsgAttachmentModel.h" |
|
27 #include "MsgAttachmentUtils.h" |
|
28 |
|
29 // ========== EXTERNAL DATA STRUCTURES ===================== |
|
30 |
|
31 // ========== EXTERNAL FUNCTION PROTOTYPES ================= |
|
32 |
|
33 // ========== CONSTANTS ==================================== |
|
34 |
|
35 // ========== MACROS ======================================= |
|
36 |
|
37 // ========== LOCAL CONSTANTS AND MACROS =================== |
|
38 |
|
39 // ========== MODULE DATA STRUCTURES ======================= |
|
40 |
|
41 // ========== LOCAL FUNCTION PROTOTYPES ==================== |
|
42 |
|
43 // ========== LOCAL FUNCTIONS ============================== |
|
44 |
|
45 // ========== MEMBER FUNCTIONS ============================= |
|
46 |
|
47 // --------------------------------------------------------- |
|
48 // CMsgAttachmentInfo::NewL |
|
49 // |
|
50 // Factory method. |
|
51 // --------------------------------------------------------- |
|
52 // |
|
53 CMsgAttachmentInfo* CMsgAttachmentInfo::NewL( |
|
54 CMsgAttachmentModel& aAttachmentModel, |
|
55 const TFileName& aFileName, |
|
56 TInt aSize, |
|
57 TBool aFetched, |
|
58 TBool aAttachedThisSession, |
|
59 TMsvAttachmentId aAttachmentId, |
|
60 const TDataType& aDataType, |
|
61 TDRMDataType aDRMDataType ) |
|
62 { |
|
63 CMsgAttachmentInfo* self = new ( ELeave ) CMsgAttachmentInfo( |
|
64 aAttachmentModel, |
|
65 aFileName, |
|
66 aSize, |
|
67 aFetched, |
|
68 aAttachedThisSession ); |
|
69 |
|
70 CleanupStack::PushL( self ); |
|
71 |
|
72 // Must be set before ConstructL is called as might be used on |
|
73 // during CMsgAttachmentModel::BitmapForFileL function call. |
|
74 self->SetAttachmentId( aAttachmentId ); |
|
75 self->ConstructL( aDataType, aDRMDataType ); |
|
76 CleanupStack::Pop(); // self |
|
77 |
|
78 return self; |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------- |
|
82 // CMsgAttachmentInfo::~CMsgAttachmentInfo |
|
83 // |
|
84 // Destructor. |
|
85 // --------------------------------------------------------- |
|
86 // |
|
87 EXPORT_C CMsgAttachmentInfo::~CMsgAttachmentInfo() |
|
88 { |
|
89 delete iIcon; |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------- |
|
93 // CMsgAttachmentInfo::FileName |
|
94 // |
|
95 // Returns reference to the filename. |
|
96 // --------------------------------------------------------- |
|
97 // |
|
98 EXPORT_C const TFileName& CMsgAttachmentInfo::FileName() const |
|
99 { |
|
100 return iFileName; |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------- |
|
104 // CMsgAttachmentInfo::SetFileName |
|
105 // |
|
106 // Set the filename of this attachment. |
|
107 // --------------------------------------------------------- |
|
108 // |
|
109 EXPORT_C void CMsgAttachmentInfo::SetFileName( const TFileName& aFileName ) |
|
110 { |
|
111 iFileName = aFileName; |
|
112 |
|
113 // find file size |
|
114 RFile file; |
|
115 RFs& fs = CEikonEnv::Static()->FsSession(); |
|
116 |
|
117 TInt err = file.Open( fs, iFileName, EFileShareAny ); |
|
118 if ( err == KErrAccessDenied || err == KErrInUse ) |
|
119 { |
|
120 err = file.Open( fs, iFileName, EFileShareReadersOnly ); |
|
121 } |
|
122 if ( err == KErrNone ) |
|
123 { |
|
124 file.Size( iSize ); |
|
125 } |
|
126 file.Close(); |
|
127 |
|
128 TRAP_IGNORE( ChangeSizeAndIconL() ); |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------- |
|
132 // CMsgAttachmentInfo::Size |
|
133 // |
|
134 // Returns the size. |
|
135 // --------------------------------------------------------- |
|
136 // |
|
137 EXPORT_C TInt CMsgAttachmentInfo::Size() const |
|
138 { |
|
139 return iSize; |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------- |
|
143 // CMsgAttachmentInfo::SizeString |
|
144 // |
|
145 // Returns the size string. |
|
146 // --------------------------------------------------------- |
|
147 // |
|
148 EXPORT_C TBuf<KMsgAttaSizeStringLength> CMsgAttachmentInfo::SizeString() const |
|
149 { |
|
150 return iSizeString; |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------- |
|
154 // CMsgAttachmentInfo::AttachmentId |
|
155 // |
|
156 // Returns the attachment id. |
|
157 // --------------------------------------------------------- |
|
158 // |
|
159 EXPORT_C TMsvAttachmentId CMsgAttachmentInfo::AttachmentId() const |
|
160 { |
|
161 return iAttachmentId; |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------- |
|
165 // CMsgAttachmentInfo::SetAttachmentId |
|
166 // |
|
167 // Sets the attachment id. |
|
168 // --------------------------------------------------------- |
|
169 // |
|
170 EXPORT_C void CMsgAttachmentInfo::SetAttachmentId( TMsvAttachmentId aId ) |
|
171 { |
|
172 iAttachmentId = aId; |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------- |
|
176 // CMsgAttachmentInfo::IsFetched |
|
177 // |
|
178 // Returns ETrue if this attachment is fetched. |
|
179 // --------------------------------------------------------- |
|
180 // |
|
181 EXPORT_C TBool CMsgAttachmentInfo::IsFetched() const |
|
182 { |
|
183 return iAttachmentFlags & EAttachmentFetched; |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------- |
|
187 // CMsgAttachmentInfo::SetFetched |
|
188 // |
|
189 // Sets the fetched attribute of this attachment. |
|
190 // --------------------------------------------------------- |
|
191 // |
|
192 EXPORT_C void CMsgAttachmentInfo::SetFetched( TBool aFetched ) |
|
193 { |
|
194 TBool updateIcon( EFalse ); |
|
195 |
|
196 if ( aFetched && !IsFetched() ) |
|
197 { |
|
198 iAttachmentFlags |= EAttachmentFetched; |
|
199 updateIcon = ETrue; |
|
200 } |
|
201 else if ( !aFetched && IsFetched() ) |
|
202 { |
|
203 iAttachmentFlags &= ~EAttachmentFetched; |
|
204 updateIcon = ETrue; |
|
205 } |
|
206 |
|
207 if ( iIcon && updateIcon ) |
|
208 { |
|
209 // No need to update icon if it's not yet initialized. |
|
210 TRAP_IGNORE( DoUpdateIconL() ); |
|
211 } |
|
212 } |
|
213 |
|
214 // --------------------------------------------------------- |
|
215 // CMsgAttachmentInfo::DataType |
|
216 // |
|
217 // Returns the datatype (MIME type) of this attachment. |
|
218 // --------------------------------------------------------- |
|
219 // |
|
220 EXPORT_C const TDataType& CMsgAttachmentInfo::DataType() const |
|
221 { |
|
222 return iDataType; |
|
223 } |
|
224 |
|
225 // --------------------------------------------------------- |
|
226 // CMsgAttachmentInfo::SetDataType |
|
227 // |
|
228 // Sets the datatype (MIME type) of this attachment. |
|
229 // --------------------------------------------------------- |
|
230 // |
|
231 EXPORT_C void CMsgAttachmentInfo::SetDataType( const TDataType& aDataType ) |
|
232 { |
|
233 if ( iDataType.Des8().CompareF( aDataType.Des8() ) != 0 ) |
|
234 { |
|
235 iDataType = aDataType; |
|
236 |
|
237 TRAP_IGNORE( DoUpdateIconL() ); |
|
238 } |
|
239 } |
|
240 |
|
241 // --------------------------------------------------------- |
|
242 // CMsgAttachmentInfo::SetDRMDataType(TDRMDataType aDRMDataType) |
|
243 // |
|
244 // Sets the DRMtype of this attachment. |
|
245 // --------------------------------------------------------- |
|
246 // |
|
247 EXPORT_C void CMsgAttachmentInfo::SetDRMDataType( TDRMDataType aDRMDataType ) |
|
248 { |
|
249 if ( iDRMDataType != aDRMDataType ) |
|
250 { |
|
251 iDRMDataType = aDRMDataType; |
|
252 |
|
253 TRAP_IGNORE( DoUpdateIconL() ); |
|
254 } |
|
255 } |
|
256 |
|
257 // --------------------------------------------------------- |
|
258 // CMsgAttachmentInfo::DRMDataType |
|
259 // |
|
260 // Returns the DRMtype of this attachment. |
|
261 // --------------------------------------------------------- |
|
262 // |
|
263 EXPORT_C TInt CMsgAttachmentInfo::DRMDataType() const |
|
264 { |
|
265 return iDRMDataType; |
|
266 } |
|
267 |
|
268 // --------------------------------------------------------- |
|
269 // CMsgAttachmentInfo::IsAttachedThisSession |
|
270 // |
|
271 // Returns ETrue if this attachment was attached in this session. |
|
272 // --------------------------------------------------------- |
|
273 // |
|
274 EXPORT_C TBool CMsgAttachmentInfo::IsAttachedThisSession() const |
|
275 { |
|
276 return iAttachmentFlags & EAttachedThisSession; |
|
277 } |
|
278 |
|
279 // --------------------------------------------------------- |
|
280 // CMsgAttachmentInfo::SetAttachedThisSession |
|
281 // |
|
282 // Sets flag which tells if this attachment is attached in this session. |
|
283 // --------------------------------------------------------- |
|
284 // |
|
285 EXPORT_C void CMsgAttachmentInfo::SetAttachedThisSession( TBool aFlag ) |
|
286 { |
|
287 if ( aFlag ) |
|
288 { |
|
289 iAttachmentFlags |= EAttachedThisSession; |
|
290 } |
|
291 else |
|
292 { |
|
293 iAttachmentFlags &= ~EAttachedThisSession; |
|
294 } |
|
295 } |
|
296 |
|
297 // --------------------------------------------------------- |
|
298 // CMsgAttachmentInfo::IsSupported |
|
299 // |
|
300 // Returns supported flag. |
|
301 // --------------------------------------------------------- |
|
302 // |
|
303 EXPORT_C TBool CMsgAttachmentInfo::IsSupported() const |
|
304 { |
|
305 return iAttachmentFlags & EAttachmentSupported; |
|
306 } |
|
307 |
|
308 // --------------------------------------------------------- |
|
309 // CMsgAttachmentInfo::SetSupported |
|
310 // |
|
311 // Sets supported flag. |
|
312 // --------------------------------------------------------- |
|
313 // |
|
314 EXPORT_C void CMsgAttachmentInfo::SetSupported( TBool aFlag ) |
|
315 { |
|
316 if ( aFlag ) |
|
317 { |
|
318 iAttachmentFlags |= EAttachmentSupported; |
|
319 } |
|
320 else |
|
321 { |
|
322 iAttachmentFlags &= ~EAttachmentSupported; |
|
323 } |
|
324 } |
|
325 |
|
326 // --------------------------------------------------------- |
|
327 // CMsgAttachmentInfo::Icon |
|
328 // |
|
329 // Returns the icon. |
|
330 // --------------------------------------------------------- |
|
331 // |
|
332 EXPORT_C CGulIcon* CMsgAttachmentInfo::Icon() const |
|
333 { |
|
334 return iIcon; |
|
335 } |
|
336 |
|
337 // --------------------------------------------------------- |
|
338 // CMsgAttachmentInfo::SetSeparator |
|
339 // |
|
340 // Returns separator flag. |
|
341 // --------------------------------------------------------- |
|
342 // |
|
343 EXPORT_C void CMsgAttachmentInfo::SetSeparator( TBool aFlag ) |
|
344 { |
|
345 if ( aFlag ) |
|
346 { |
|
347 iAttachmentFlags |= ESeparatorBefore; |
|
348 } |
|
349 else |
|
350 { |
|
351 iAttachmentFlags &= ~ESeparatorBefore; |
|
352 } |
|
353 } |
|
354 |
|
355 // --------------------------------------------------------- |
|
356 // CMsgAttachmentInfo::IsSeparator |
|
357 // |
|
358 // Sets separator flag. |
|
359 // --------------------------------------------------------- |
|
360 // |
|
361 EXPORT_C TBool CMsgAttachmentInfo::IsSeparator() const |
|
362 { |
|
363 return iAttachmentFlags & ESeparatorBefore;; |
|
364 } |
|
365 |
|
366 // --------------------------------------------------------- |
|
367 // CMsgAttachmentInfo::CMsgAttachmentInfo |
|
368 // |
|
369 // Constructor. |
|
370 // --------------------------------------------------------- |
|
371 // |
|
372 EXPORT_C CMsgAttachmentInfo::CMsgAttachmentInfo( CMsgAttachmentModel& aAttachmentModel, |
|
373 const TFileName& aFileName, |
|
374 TInt aSize, |
|
375 TBool aFetched, |
|
376 TBool aAttachedThisSession ) : |
|
377 iAttachmentModel( aAttachmentModel ), |
|
378 iFileName( aFileName ), |
|
379 iSize( aSize ), |
|
380 iCharset( KErrNotFound ) |
|
381 { |
|
382 SetFetched( aFetched ); |
|
383 SetAttachedThisSession ( aAttachedThisSession ); |
|
384 SetSupported( ETrue ); |
|
385 } |
|
386 |
|
387 // --------------------------------------------------------- |
|
388 // CMsgAttachmentInfo::ConstructL |
|
389 // |
|
390 // |
|
391 // --------------------------------------------------------- |
|
392 // |
|
393 EXPORT_C void CMsgAttachmentInfo::ConstructL( const TDataType& aDataType, |
|
394 TDRMDataType aDRMDataType ) |
|
395 { |
|
396 iDataType = aDataType; |
|
397 iDRMDataType = aDRMDataType; |
|
398 ChangeSizeAndIconL(); |
|
399 } |
|
400 |
|
401 // --------------------------------------------------------- |
|
402 // CMsgAttachmentInfo::ChangeSizeAndIconL |
|
403 // |
|
404 // |
|
405 // --------------------------------------------------------- |
|
406 // |
|
407 void CMsgAttachmentInfo::ChangeSizeAndIconL() |
|
408 { |
|
409 MsgAttachmentUtils::FileSizeToStringL( iSizeString, iSize ); |
|
410 |
|
411 DoUpdateIconL(); |
|
412 } |
|
413 |
|
414 |
|
415 // --------------------------------------------------------- |
|
416 // CMsgAttachmentInfo::SetSaved |
|
417 // |
|
418 // |
|
419 // --------------------------------------------------------- |
|
420 // |
|
421 EXPORT_C void CMsgAttachmentInfo::SetSaved( TBool aSaved ) |
|
422 { |
|
423 if ( aSaved ) |
|
424 { |
|
425 iAttachmentFlags |= EAttachmentSaved; |
|
426 } |
|
427 else |
|
428 { |
|
429 iAttachmentFlags &= ~EAttachmentSaved; |
|
430 } |
|
431 } |
|
432 |
|
433 // --------------------------------------------------------- |
|
434 // CMsgAttachmentInfo::IsSaved |
|
435 // |
|
436 // |
|
437 // --------------------------------------------------------- |
|
438 // |
|
439 EXPORT_C TBool CMsgAttachmentInfo::IsSaved( ) const |
|
440 { |
|
441 return iAttachmentFlags & EAttachmentSaved; |
|
442 } |
|
443 |
|
444 // --------------------------------------------------------- |
|
445 // CMsgAttachmentInfo::DoUpdateIconL |
|
446 // |
|
447 // |
|
448 // --------------------------------------------------------- |
|
449 // |
|
450 void CMsgAttachmentInfo::DoUpdateIconL() |
|
451 { |
|
452 CGulIcon* resultIcon = iAttachmentModel.BitmapForFileL( *this ); |
|
453 |
|
454 // icons are owned by atta info object. |
|
455 delete iIcon; |
|
456 iIcon = resultIcon; |
|
457 } |
|
458 |
|
459 // ========== OTHER EXPORTED FUNCTIONS ===================== |
|
460 |
|
461 // End of File |