|
1 /* |
|
2 * Copyright (c) 2005 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 * Data utility class for UniEditor & MMS related editors and viewers |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // ========== INCLUDE FILES ================================ |
|
22 |
|
23 #include <e32std.h> |
|
24 #include <e32base.h> |
|
25 #include <f32file.h> |
|
26 #include <data_caging_path_literals.hrh> |
|
27 |
|
28 #include <bautils.h> |
|
29 |
|
30 #include <mtclbase.h> |
|
31 #include <msvstore.h> |
|
32 #include <mmsvattachmentmanager.h> |
|
33 #include <cmsvattachment.h> |
|
34 #include <cmsvmimeheaders.h> |
|
35 |
|
36 #include <StringLoader.h> // for StringLoader (load and foramt strings from resources) |
|
37 #include <CommonContentPolicy.h> |
|
38 |
|
39 #include <UniDataModel.rsg> // Viewer/Editor Mimetype strings |
|
40 |
|
41 #include "UniModelConst.h" |
|
42 #include "UniDataUtils.h" |
|
43 #include "msgtextutils.h" |
|
44 #include "MsgMimeTypes.h" |
|
45 |
|
46 // ========== LOCAL CONSTANTS AND MACROS =================== |
|
47 |
|
48 const TInt KTextBufferMaxSize( 256 ); // Max size for string read from resources. |
|
49 // NOTE: This is 256 unicode chars, too. |
|
50 |
|
51 // ========== MEMBER FUNCTIONS ============================= |
|
52 |
|
53 |
|
54 // --------------------------------------------------------- |
|
55 // CUniDataUtils::NewL |
|
56 // --------------------------------------------------------- |
|
57 // |
|
58 EXPORT_C CUniDataUtils* CUniDataUtils::NewL( RFs& aFs ) |
|
59 { |
|
60 CUniDataUtils* data = new ( ELeave ) CUniDataUtils( aFs ); |
|
61 CleanupStack::PushL( data ); |
|
62 data->ConstructL(); |
|
63 CleanupStack::Pop( data ); |
|
64 return data; |
|
65 } |
|
66 |
|
67 |
|
68 // --------------------------------------------------------- |
|
69 // CUniDataUtils::CUniDataUtils |
|
70 // |
|
71 // Constructor |
|
72 // --------------------------------------------------------- |
|
73 // |
|
74 CUniDataUtils::CUniDataUtils( RFs& aFs ) |
|
75 : iFs( aFs ) |
|
76 { |
|
77 } |
|
78 |
|
79 |
|
80 // --------------------------------------------------------- |
|
81 // CUniDataUtils::ConstructL |
|
82 // --------------------------------------------------------- |
|
83 // |
|
84 void CUniDataUtils::ConstructL() |
|
85 { |
|
86 RegisterDataL(); |
|
87 iTextUtils = CMsgTextUtils::NewL( iFs ); |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------- |
|
91 // CUniDataUtils::~CUniDataUtils |
|
92 // |
|
93 // Destructor. |
|
94 // --------------------------------------------------------- |
|
95 // |
|
96 CUniDataUtils::~CUniDataUtils() |
|
97 { |
|
98 delete iDefaultFileName; |
|
99 delete iEmptyPageString; |
|
100 delete iTextUtils; |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------- |
|
104 // CUniDataUtils::CharconvIdToMibIdL |
|
105 // --------------------------------------------------------- |
|
106 // |
|
107 EXPORT_C TUint CUniDataUtils::CharconvIdToMibIdL( TUint aCharconvCharsetId ) |
|
108 { |
|
109 return iTextUtils->CharconvIdToMibIdL( aCharconvCharsetId ); |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------- |
|
113 // CUniDataUtils::MibIdToCharconvIdL |
|
114 // --------------------------------------------------------- |
|
115 // |
|
116 EXPORT_C TUint CUniDataUtils::MibIdToCharconvIdL( TUint aMibId ) |
|
117 { |
|
118 return iTextUtils->MibIdToCharconvIdL( aMibId ); |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------- |
|
122 // CUniDataUtils::UTF8Size |
|
123 // --------------------------------------------------------- |
|
124 EXPORT_C TInt CUniDataUtils::UTF8Size( TPtrC aText ) |
|
125 { |
|
126 return CMsgTextUtils::UTF8Size( aText ); |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------- |
|
130 // CUniDataUtils::RegisterDataL |
|
131 // |
|
132 // Registers data |
|
133 // --------------------------------------------------------- |
|
134 // |
|
135 void CUniDataUtils::RegisterDataL() |
|
136 { |
|
137 TFileName fileName; |
|
138 TParse parse; |
|
139 parse.Set( KUniDataModelResourceFilename, &KDC_RESOURCE_FILES_DIR, NULL ); |
|
140 fileName = parse.FullName(); |
|
141 |
|
142 BaflUtils::NearestLanguageFile( iFs, fileName ); |
|
143 |
|
144 RResourceFile resourceFile; |
|
145 resourceFile.OpenL( const_cast<RFs&>( iFs ), fileName ); |
|
146 resourceFile.ConfirmSignatureL( KDefResFileSignature ); |
|
147 CleanupClosePushL( resourceFile ); |
|
148 |
|
149 iDefaultFileName = ReadResStringL( resourceFile, R_MMDU_DEFAULT_FILE_NAME ); |
|
150 iEmptyPageString = ReadResStringL( resourceFile, R_MMDU_EMPTY_SLIDE ); |
|
151 |
|
152 CleanupStack::PopAndDestroy( &resourceFile ); |
|
153 } |
|
154 |
|
155 |
|
156 // --------------------------------------------------------- |
|
157 // CUniDataUtils::ReadResStringL |
|
158 // |
|
159 // Read single string. |
|
160 // --------------------------------------------------------- |
|
161 // |
|
162 HBufC* CUniDataUtils::ReadResStringL( const RResourceFile& aResourceFile, TInt aSrcResId ) |
|
163 { |
|
164 HBufC* readBuf = HBufC::NewLC( KTextBufferMaxSize ); |
|
165 TPtr8 readBuffer( (TText8*) readBuf->Ptr(), KTextBufferMaxSize * 2 ); |
|
166 aResourceFile.ReadL(readBuffer, (0x00000fff & aSrcResId) ); // Remove offset from id |
|
167 |
|
168 if ( readBuffer.Length() != 0 ) |
|
169 { |
|
170 readBuf->Des().SetLength((readBuffer.Length()+1)>>1); |
|
171 } |
|
172 |
|
173 CleanupStack::Pop( readBuf ); |
|
174 return readBuf; |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------- |
|
178 // FileSizeL |
|
179 // --------------------------------------------------------- |
|
180 EXPORT_C TInt CUniDataUtils::FileSizeL( const TFileName& aFileName ) |
|
181 { |
|
182 TInt size(0); |
|
183 RFile file; |
|
184 |
|
185 TInt err = file.Open( iFs, aFileName, EFileShareAny ); |
|
186 if ( err == KErrAccessDenied || err == KErrInUse ) |
|
187 { |
|
188 err = file.Open( iFs, aFileName, EFileShareReadersOnly ); |
|
189 } |
|
190 if ( err == KErrNone ) |
|
191 { |
|
192 file.Size( size ); |
|
193 } |
|
194 else |
|
195 { |
|
196 file.Close(); |
|
197 User::Leave( err ); |
|
198 } |
|
199 |
|
200 file.Close(); |
|
201 return size; |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------- |
|
205 // CUniObject::GetAttachmentFileL |
|
206 // --------------------------------------------------------- |
|
207 // |
|
208 EXPORT_C RFile CUniDataUtils::GetAttachmentFileL( CBaseMtm& aMtm, TMsvAttachmentId aId ) |
|
209 { |
|
210 RFile file; |
|
211 CMsvStore* store = aMtm.Entry().ReadStoreL(); |
|
212 CleanupStack::PushL( store ); |
|
213 MMsvAttachmentManager& manager = store->AttachmentManagerL(); |
|
214 file = manager.GetAttachmentFileL( aId ); |
|
215 CleanupStack::PopAndDestroy( store ); |
|
216 |
|
217 return file; |
|
218 } |
|
219 |
|
220 // --------------------------------------------------------- |
|
221 // CUniObject::IndexPositionOfAttachmentL |
|
222 // --------------------------------------------------------- |
|
223 // |
|
224 EXPORT_C TInt CUniDataUtils::IndexPositionOfAttachmentL( |
|
225 MMsvAttachmentManager& aManager, |
|
226 TMsvAttachmentId aId ) |
|
227 { |
|
228 TInt count = aManager.AttachmentCount(); |
|
229 TInt foundPosition = KErrNotFound; |
|
230 |
|
231 for ( TInt i = 0; i < count; ++i ) |
|
232 { |
|
233 CMsvAttachment* attachment = aManager.GetAttachmentInfoL( i ); |
|
234 TMsvAttachmentId id = attachment->Id(); |
|
235 delete attachment; |
|
236 if ( id == aId ) |
|
237 { |
|
238 foundPosition = i; |
|
239 break; |
|
240 } |
|
241 } |
|
242 |
|
243 // Leave with KErrNotFound if the attachment id is not found |
|
244 User::LeaveIfError( foundPosition ); |
|
245 |
|
246 // return the index position of attachment |
|
247 return foundPosition; |
|
248 } |
|
249 |
|
250 // End of File |