|
1 /* |
|
2 * Copyright (c) 2005-2007 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: |
|
15 * Provides methods for the Image data abstraction hierarchy. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPbk2ImageData.h" |
|
22 |
|
23 // From Phonebook2 |
|
24 #include "CPbk2AttachmentFile.h" |
|
25 |
|
26 // From System |
|
27 #include <f32file.h> |
|
28 |
|
29 // ================= MEMBER FUNCTIONS ======================= |
|
30 |
|
31 // -------------------------------------------------------------------------- |
|
32 // CPbk2ImageFileData::CPbk2ImageFileData |
|
33 // -------------------------------------------------------------------------- |
|
34 // |
|
35 inline CPbk2ImageFileData::CPbk2ImageFileData(const TDesC& aFileName) |
|
36 { |
|
37 iFileName.Copy(aFileName.Left(iFileName.MaxLength())); |
|
38 } |
|
39 |
|
40 // -------------------------------------------------------------------------- |
|
41 // CPbk2ImageFileData::~CPbk2ImageFileData |
|
42 // -------------------------------------------------------------------------- |
|
43 // |
|
44 CPbk2ImageFileData::~CPbk2ImageFileData() |
|
45 { |
|
46 delete iBuffer; |
|
47 } |
|
48 |
|
49 // -------------------------------------------------------------------------- |
|
50 // CPbk2ImageFileData::NewL |
|
51 // -------------------------------------------------------------------------- |
|
52 // |
|
53 CPbk2ImageFileData* CPbk2ImageFileData::NewL(const TDesC& aFileName) |
|
54 { |
|
55 return new(ELeave) CPbk2ImageFileData(aFileName); |
|
56 } |
|
57 |
|
58 // -------------------------------------------------------------------------- |
|
59 // CPbk2ImageFileData::GetBufferL |
|
60 // -------------------------------------------------------------------------- |
|
61 // |
|
62 const TDesC8& CPbk2ImageFileData::GetBufferL() const |
|
63 { |
|
64 if (!iBuffer) |
|
65 { |
|
66 RFs fsSession; |
|
67 User::LeaveIfError(fsSession.Connect()); |
|
68 CleanupClosePushL(fsSession); |
|
69 RFile file; |
|
70 User::LeaveIfError( file.Open( |
|
71 fsSession, iFileName, EFileRead|EFileShareReadersOnly ) ); |
|
72 CleanupClosePushL(file); |
|
73 TInt fileSize; |
|
74 User::LeaveIfError(file.Size(fileSize)); |
|
75 HBufC8* buf = HBufC8::NewLC(fileSize); |
|
76 TPtr8 bufPtr(buf->Des()); |
|
77 User::LeaveIfError(file.Read(bufPtr)); |
|
78 CleanupStack::Pop(buf); |
|
79 iBuffer = buf; |
|
80 CleanupStack::PopAndDestroy(2); // file, fsSession |
|
81 } |
|
82 return *iBuffer; |
|
83 } |
|
84 |
|
85 // -------------------------------------------------------------------------- |
|
86 // CPbk2ImageFileData::GetFileNameL |
|
87 // -------------------------------------------------------------------------- |
|
88 // |
|
89 const TDesC& CPbk2ImageFileData::GetFileNameL() const |
|
90 { |
|
91 return iFileName; |
|
92 } |
|
93 |
|
94 // -------------------------------------------------------------------------- |
|
95 // CPbk2ImageBufferData::CPbk2ImageBufferData |
|
96 // -------------------------------------------------------------------------- |
|
97 // |
|
98 inline CPbk2ImageBufferData::CPbk2ImageBufferData |
|
99 (const TDesC8& aBuffer, const TDesC& aBaseName) : |
|
100 iBuffer(aBuffer) |
|
101 { |
|
102 iBaseName.Copy(aBaseName.Left(iBaseName.MaxLength())); |
|
103 } |
|
104 |
|
105 // -------------------------------------------------------------------------- |
|
106 // CPbk2ImageBufferData::~CPbk2ImageBufferData |
|
107 // -------------------------------------------------------------------------- |
|
108 // |
|
109 CPbk2ImageBufferData::~CPbk2ImageBufferData() |
|
110 { |
|
111 delete iFile; |
|
112 iFsSession.Close(); |
|
113 } |
|
114 |
|
115 // -------------------------------------------------------------------------- |
|
116 // CPbk2ImageBufferData::NewL |
|
117 // -------------------------------------------------------------------------- |
|
118 // |
|
119 CPbk2ImageBufferData* CPbk2ImageBufferData::NewL |
|
120 (const TDesC8& aBuffer, const TDesC& aBaseName/*=KNullDesC*/) |
|
121 { |
|
122 CPbk2ImageBufferData* self = |
|
123 new(ELeave) CPbk2ImageBufferData(aBuffer,aBaseName); |
|
124 return self; |
|
125 } |
|
126 |
|
127 // -------------------------------------------------------------------------- |
|
128 // CPbk2ImageBufferData::GetBufferL |
|
129 // -------------------------------------------------------------------------- |
|
130 // |
|
131 const TDesC8& CPbk2ImageBufferData::GetBufferL() const |
|
132 { |
|
133 return iBuffer; |
|
134 } |
|
135 |
|
136 // -------------------------------------------------------------------------- |
|
137 // CPbk2ImageBufferData::GetFileNameL |
|
138 // -------------------------------------------------------------------------- |
|
139 // |
|
140 const TDesC& CPbk2ImageBufferData::GetFileNameL() const |
|
141 { |
|
142 if (!iFile) |
|
143 { |
|
144 if (iFsSession.Handle() == KNullHandle) |
|
145 { |
|
146 User::LeaveIfError(iFsSession.Connect()); |
|
147 } |
|
148 CPbk2AttachmentFile* imageFile = |
|
149 CPbk2AttachmentFile::NewLC(iBaseName,iFsSession); |
|
150 RFile& file = imageFile->File(); |
|
151 User::LeaveIfError(file.Write(iBuffer)); |
|
152 User::LeaveIfError(file.Flush()); |
|
153 file.Close(); |
|
154 CleanupStack::Pop(imageFile); |
|
155 iFile = imageFile; |
|
156 } |
|
157 return iFile->FileName(); |
|
158 } |
|
159 |
|
160 // End of File |