|
1 /* |
|
2 * Copyright (c) 2009 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 : Attachment information |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <eikenv.h> |
|
19 #include <gulicon.h> |
|
20 #include <avkon.rsg> |
|
21 #include <StringLoader.h> // StringLoader |
|
22 |
|
23 #include "calenattachmentinfo.h" |
|
24 #include "calenattachmentmodel.h" |
|
25 #include "calenattachmentutils.h" |
|
26 #include "calendarui_debug.h" |
|
27 |
|
28 // ---------------------------------------------------------------------------- |
|
29 // CCalenAttachmentInfo::NewL |
|
30 // First phase construction |
|
31 // ---------------------------------------------------------------------------- |
|
32 // |
|
33 EXPORT_C CCalenAttachmentInfo* CCalenAttachmentInfo::NewL( |
|
34 CCalenAttachmentModel& aAttachmentModel, |
|
35 const TFileName& aFileName, |
|
36 const TFileName& aSystemFileName, |
|
37 TInt aSize, |
|
38 TBool aFetched, |
|
39 const TDataType& aDataType, |
|
40 TCalenAttachmentStoreType aStoreType ) |
|
41 { |
|
42 TRACE_ENTRY_POINT; |
|
43 |
|
44 CCalenAttachmentInfo* self = new ( ELeave ) CCalenAttachmentInfo( |
|
45 aAttachmentModel, |
|
46 aFileName, |
|
47 aSystemFileName, |
|
48 aSize, |
|
49 aFetched, |
|
50 aDataType, |
|
51 aStoreType); |
|
52 CleanupStack::PushL( self ); |
|
53 self->ConstructL(); |
|
54 CleanupStack::Pop(); |
|
55 |
|
56 TRACE_EXIT_POINT; |
|
57 return self; |
|
58 } |
|
59 |
|
60 // ---------------------------------------------------------------------------- |
|
61 // CCalenAttachmentInfo::~CCalenAttachmentInfo |
|
62 // Destructor. |
|
63 // ---------------------------------------------------------------------------- |
|
64 // |
|
65 CCalenAttachmentInfo::~CCalenAttachmentInfo() |
|
66 { |
|
67 TRACE_ENTRY_POINT; |
|
68 TRACE_EXIT_POINT; |
|
69 delete iIcon; |
|
70 if(isSetFileHandle) |
|
71 { |
|
72 iFile.Close(); |
|
73 } |
|
74 } |
|
75 |
|
76 // ---------------------------------------------------------------------------- |
|
77 // CCalenAttachmentInfo::CCalenAttachmentInfo |
|
78 // Constructor. |
|
79 // ---------------------------------------------------------------------------- |
|
80 // |
|
81 CCalenAttachmentInfo::CCalenAttachmentInfo( CCalenAttachmentModel& aAttachmentModel, |
|
82 const TFileName& aFileName, |
|
83 const TFileName& aSystemFileName, |
|
84 TInt aSize, |
|
85 TBool aFetched, |
|
86 const TDataType& aDataType, |
|
87 TCalenAttachmentStoreType aStoreType) |
|
88 : iAttachmentModel(aAttachmentModel), |
|
89 iFileName(aFileName), |
|
90 iSystemFileName(aSystemFileName), |
|
91 iSize(aSize), |
|
92 iDataType(aDataType), |
|
93 iAttachmentStoreType(aStoreType) |
|
94 { |
|
95 TRACE_ENTRY_POINT; |
|
96 |
|
97 SetFetched( aFetched ); |
|
98 |
|
99 TRACE_EXIT_POINT; |
|
100 } |
|
101 |
|
102 // ---------------------------------------------------------------------------- |
|
103 // CCalenAttachmentInfo::ConstructL |
|
104 // Second phase construction |
|
105 // ---------------------------------------------------------------------------- |
|
106 // |
|
107 void CCalenAttachmentInfo::ConstructL() |
|
108 { |
|
109 TRACE_ENTRY_POINT; |
|
110 |
|
111 DoUpdateIconL(); |
|
112 |
|
113 TRACE_EXIT_POINT; |
|
114 } |
|
115 |
|
116 // ---------------------------------------------------------------------------- |
|
117 // CCalenAttachmentInfo::FileName |
|
118 // Returns reference to the filename. |
|
119 // ---------------------------------------------------------------------------- |
|
120 // |
|
121 EXPORT_C const TFileName& CCalenAttachmentInfo::FileName() const |
|
122 { |
|
123 TRACE_ENTRY_POINT; |
|
124 TRACE_EXIT_POINT; |
|
125 |
|
126 return iFileName; |
|
127 } |
|
128 |
|
129 // ---------------------------------------------------------------------------- |
|
130 // CCalenAttachmentInfo::SetFileName |
|
131 // Set the filename of this attachment. |
|
132 // ---------------------------------------------------------------------------- |
|
133 // |
|
134 EXPORT_C void CCalenAttachmentInfo::SetFileName( const TFileName& aFileName ) |
|
135 { |
|
136 TRACE_ENTRY_POINT; |
|
137 |
|
138 iFileName = aFileName; |
|
139 |
|
140 // find file size |
|
141 RFile file; |
|
142 RFs& fs = CEikonEnv::Static()->FsSession(); |
|
143 |
|
144 TInt err = file.Open( fs, iFileName, EFileShareAny ); |
|
145 if ( err == KErrAccessDenied || err == KErrInUse ) |
|
146 { |
|
147 err = file.Open( fs, iFileName, EFileShareReadersOnly ); |
|
148 } |
|
149 if ( err == KErrNone ) |
|
150 { |
|
151 file.Size( iSize ); |
|
152 } |
|
153 file.Close(); |
|
154 |
|
155 TRAP_IGNORE( DoUpdateIconL() ); |
|
156 |
|
157 TRACE_EXIT_POINT; |
|
158 } |
|
159 |
|
160 // ---------------------------------------------------------------------------- |
|
161 // CCalenAttachmentInfo::Size |
|
162 // Returns the size. |
|
163 // ---------------------------------------------------------------------------- |
|
164 // |
|
165 EXPORT_C TInt CCalenAttachmentInfo::Size() const |
|
166 { |
|
167 TRACE_ENTRY_POINT; |
|
168 TRACE_EXIT_POINT; |
|
169 return iSize; |
|
170 } |
|
171 |
|
172 // ---------------------------------------------------------------------------- |
|
173 // CCalenAttachmentInfo::Size |
|
174 // Returns the size in the form of descriptor to be shown on the UI. |
|
175 // Owner ship of the size string is transfered. |
|
176 // ---------------------------------------------------------------------------- |
|
177 // |
|
178 EXPORT_C HBufC* CCalenAttachmentInfo::SizeString() const |
|
179 { |
|
180 TRACE_ENTRY_POINT; |
|
181 TInt resId = R_QTN_SIZE_B; |
|
182 TInt fileSize = iSize; |
|
183 if ( fileSize >= KLocalKilo ) |
|
184 { |
|
185 resId = R_QTN_SIZE_KB; |
|
186 fileSize /= KLocalKilo; |
|
187 if ( iSize % KLocalKilo ) |
|
188 { |
|
189 fileSize++; |
|
190 } |
|
191 } |
|
192 |
|
193 HBufC *buf = StringLoader::LoadLC( resId, fileSize ); |
|
194 CleanupStack::Pop( buf ); |
|
195 TRACE_EXIT_POINT; |
|
196 return buf; |
|
197 } |
|
198 |
|
199 // ---------------------------------------------------------------------------- |
|
200 // CCalenAttachmentInfo::IsFetched |
|
201 // Returns ETrue if this attachment is fetched. |
|
202 // ---------------------------------------------------------------------------- |
|
203 // |
|
204 EXPORT_C TBool CCalenAttachmentInfo::IsFetched() const |
|
205 { |
|
206 TRACE_ENTRY_POINT; |
|
207 TRACE_EXIT_POINT; |
|
208 return iIsFetched; |
|
209 } |
|
210 |
|
211 // ---------------------------------------------------------------------------- |
|
212 // CCalenAttachmentInfo::SetFetched |
|
213 // Sets the fetched attribute of this attachment. |
|
214 // ---------------------------------------------------------------------------- |
|
215 // |
|
216 EXPORT_C void CCalenAttachmentInfo::SetFetched( TBool aFetched ) |
|
217 { |
|
218 TRACE_ENTRY_POINT; |
|
219 |
|
220 iIsFetched = aFetched; |
|
221 |
|
222 if(iIcon) |
|
223 { |
|
224 TRAP_IGNORE( DoUpdateIconL() ); |
|
225 } |
|
226 |
|
227 TRACE_EXIT_POINT; |
|
228 } |
|
229 |
|
230 // ---------------------------------------------------------------------------- |
|
231 // CCalenAttachmentInfo::DataType |
|
232 // Returns the datatype (MIME type) of this attachment. |
|
233 // ---------------------------------------------------------------------------- |
|
234 // |
|
235 EXPORT_C const TDataType& CCalenAttachmentInfo::DataType() const |
|
236 { |
|
237 TRACE_ENTRY_POINT; |
|
238 TRACE_EXIT_POINT; |
|
239 return iDataType; |
|
240 } |
|
241 |
|
242 // ---------------------------------------------------------------------------- |
|
243 // CCalenAttachmentInfo::Icon |
|
244 // Returns the icon. |
|
245 // ---------------------------------------------------------------------------- |
|
246 // |
|
247 EXPORT_C CGulIcon* CCalenAttachmentInfo::Icon() const |
|
248 { |
|
249 TRACE_ENTRY_POINT; |
|
250 TRACE_EXIT_POINT; |
|
251 return iIcon; |
|
252 } |
|
253 |
|
254 // ---------------------------------------------------------------------------- |
|
255 // CCalenAttachmentInfo::DoUpdateIconL |
|
256 // Update the attachment icon |
|
257 // ---------------------------------------------------------------------------- |
|
258 // |
|
259 void CCalenAttachmentInfo::DoUpdateIconL() |
|
260 { |
|
261 TRACE_ENTRY_POINT; |
|
262 |
|
263 CGulIcon* resultIcon = iAttachmentModel.BitmapForFileL( *this ); |
|
264 |
|
265 // icons are owned by atta info object. |
|
266 delete iIcon; |
|
267 iIcon = resultIcon; |
|
268 |
|
269 TRACE_EXIT_POINT; |
|
270 } |
|
271 |
|
272 // ---------------------------------------------------------------------------- |
|
273 // CCalenAttachmentInfo::StoreType |
|
274 // Returns the store type of the attachment |
|
275 // ---------------------------------------------------------------------------- |
|
276 // |
|
277 EXPORT_C CCalenAttachmentInfo::TCalenAttachmentStoreType |
|
278 CCalenAttachmentInfo::StoreType() const |
|
279 { |
|
280 TRACE_ENTRY_POINT; |
|
281 TRACE_EXIT_POINT; |
|
282 |
|
283 return iAttachmentStoreType; |
|
284 } |
|
285 |
|
286 // ---------------------------------------------------------------------------- |
|
287 // CCalenAttachmentInfo::SystemFileName |
|
288 // Returns reference to the filename. |
|
289 // ---------------------------------------------------------------------------- |
|
290 // |
|
291 EXPORT_C const TFileName& CCalenAttachmentInfo::SystemFileName() const |
|
292 { |
|
293 TRACE_ENTRY_POINT; |
|
294 TRACE_EXIT_POINT; |
|
295 |
|
296 return iSystemFileName; |
|
297 } |
|
298 |
|
299 // ---------------------------------------------------------------------------- |
|
300 // CCalenAttachmentInfo::SetFileHandle |
|
301 // |
|
302 //Sets the file handle |
|
303 // ---------------------------------------------------------------------------- |
|
304 // |
|
305 void CCalenAttachmentInfo::SetFileHandle(RFile& aFile) |
|
306 { |
|
307 TRACE_ENTRY_POINT; |
|
308 iFile.Duplicate(aFile); |
|
309 isSetFileHandle = ETrue; |
|
310 TRACE_EXIT_POINT; |
|
311 } |
|
312 |
|
313 // ---------------------------------------------------------------------------- |
|
314 // CCalenAttachmentInfo::FileHandle |
|
315 // |
|
316 //Gets the file handle. |
|
317 // ---------------------------------------------------------------------------- |
|
318 // |
|
319 void CCalenAttachmentInfo::FileHandle( RFile& aFile ) |
|
320 { |
|
321 TRACE_ENTRY_POINT; |
|
322 |
|
323 aFile.Duplicate( iFile ); |
|
324 TRACE_EXIT_POINT; |
|
325 } |
|
326 |
|
327 // ---------------------------------------------------------------------------- |
|
328 // CCalenAttachmentInfo::IsFileHandleSet |
|
329 // ---------------------------------------------------------------------------- |
|
330 // |
|
331 TBool CCalenAttachmentInfo::IsFileHandleSet() |
|
332 { |
|
333 TRACE_ENTRY_POINT; |
|
334 TRACE_EXIT_POINT; |
|
335 |
|
336 return isSetFileHandle; |
|
337 } |
|
338 |
|
339 //end of file |
|
340 |
|
341 |