1 /* |
|
2 * Copyright (c) 2008 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: Implementation of the class CPbkxRclvCardSender. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "emailtrace.h" |
|
20 #include <sendui.h> |
|
21 #include <BCardEng.h> |
|
22 #include <CPbkContactEngine.h> |
|
23 #include <CPbkContactItem.h> |
|
24 #include <eikenv.h> |
|
25 #include <featmgr.h> |
|
26 #include <features.hrh> |
|
27 #include <s32file.h> |
|
28 #include <CMessageData.h> |
|
29 #include <txtrich.h> |
|
30 #include <MsgBioUids.h> |
|
31 #include <SendUiConsts.h> |
|
32 |
|
33 #include "cpbkxrclvcardsender.h" |
|
34 #include "cpbkxrclcontactconverter.h" |
|
35 #include "pbkxrclengineconstants.h" |
|
36 #include "pbkxremotecontactlookuppanic.h" |
|
37 |
|
38 // temp file created for the business card to be sent |
|
39 //<cmail> file path is not hardcoded |
|
40 _LIT( KVcardExtension, ".vcf" ); |
|
41 #include <pathinfo.h> |
|
42 //</cmail> |
|
43 |
|
44 // ======== MEMBER FUNCTIONS ======== |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // CPbkxRclvCardSender::NewL |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 CPbkxRclvCardSender* CPbkxRclvCardSender::NewL( |
|
51 CPbkContactEngine& aContactEngine ) |
|
52 { |
|
53 FUNC_LOG; |
|
54 CPbkxRclvCardSender* sender = CPbkxRclvCardSender::NewLC( aContactEngine ); |
|
55 CleanupStack::Pop( sender ); |
|
56 return sender; |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // CPbkxRclvCardSender::NewLC |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 CPbkxRclvCardSender* CPbkxRclvCardSender::NewLC( |
|
64 CPbkContactEngine& aContactEngine ) |
|
65 { |
|
66 FUNC_LOG; |
|
67 CPbkxRclvCardSender* sender = new ( ELeave ) CPbkxRclvCardSender(); |
|
68 CleanupStack::PushL( sender ); |
|
69 sender->ConstructL( aContactEngine ); |
|
70 return sender; |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // CPbkxRclvCardSender::CPbkxRclvCardSender |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 CPbkxRclvCardSender::CPbkxRclvCardSender() : CBase() |
|
78 { |
|
79 FUNC_LOG; |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // CPbkxRclvCardSender::~CPbkxRclvCardSender |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 CPbkxRclvCardSender::~CPbkxRclvCardSender() |
|
87 { |
|
88 FUNC_LOG; |
|
89 delete iSendUi; |
|
90 delete iCardEngine; |
|
91 delete iFilter; |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // CPbkxRclvCardSender::ConstructL |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 void CPbkxRclvCardSender::ConstructL( CPbkContactEngine& aContactEngine ) |
|
99 { |
|
100 FUNC_LOG; |
|
101 iEikEnv = CEikonEnv::Static(); |
|
102 |
|
103 __ASSERT_ALWAYS( iEikEnv != NULL, PbkxRclPanic( EPbkxRclPanicGeneral ) ); |
|
104 |
|
105 iSendUi = CSendUi::NewL(); |
|
106 iCardEngine = CBCardEngine::NewL( &aContactEngine ); |
|
107 CreateFilterL(); |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // CPbkxRclvCardSender::SendvCardL |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 void CPbkxRclvCardSender::SendvCardL( |
|
115 CPbkContactItem& aContactItem, |
|
116 CPbkxRclContactConverter& aContactConverter ) |
|
117 { |
|
118 FUNC_LOG; |
|
119 User::LeaveIfError( GetTemporaryFileNameL( iTempFileName, aContactItem ) ); |
|
120 CreateTempFileL( aContactItem, aContactConverter ); |
|
121 |
|
122 TUid mtmUid = iSendUi->ShowSendQueryL( |
|
123 NULL, |
|
124 KCapabilitiesForAllServices, |
|
125 iFilter ); |
|
126 |
|
127 if ( mtmUid == KNullUid ) |
|
128 { |
|
129 // user pressed cancel |
|
130 DestroyTempFileL(); |
|
131 return; |
|
132 } |
|
133 |
|
134 CMessageData* messageData = CMessageData::NewLC(); |
|
135 |
|
136 //<cmail> |
|
137 RFs fs; |
|
138 RFile attachament; |
|
139 |
|
140 User::LeaveIfError( fs.Connect() ); |
|
141 CleanupClosePushL( fs ); |
|
142 User::LeaveIfError( attachament.Open( fs, iTempFileName, EFileShareAny ) ); |
|
143 CleanupClosePushL( attachament ); |
|
144 |
|
145 messageData->AppendAttachmentHandleL( attachament ); |
|
146 |
|
147 // Send the message using Send Ui |
|
148 iSendUi->CreateAndSendMessageL( mtmUid, messageData, KMsgBioUidVCard ); |
|
149 |
|
150 CleanupStack::PopAndDestroy( &attachament ); |
|
151 CleanupStack::PopAndDestroy( &fs ); |
|
152 CleanupStack::PopAndDestroy( messageData ); |
|
153 |
|
154 //</cmail> |
|
155 |
|
156 DestroyTempFileL(); |
|
157 |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // CPbkxRclvCardSender::CreateTempFileL |
|
162 // --------------------------------------------------------------------------- |
|
163 // |
|
164 void CPbkxRclvCardSender::CreateTempFileL( |
|
165 CPbkContactItem& aContactItem, |
|
166 CPbkxRclContactConverter& aContactConverter ) |
|
167 { |
|
168 FUNC_LOG; |
|
169 RFileWriteStream stream; |
|
170 User::LeaveIfError( |
|
171 stream.Replace( |
|
172 iEikEnv->FsSession(), |
|
173 iTempFileName, //<cmail> |
|
174 EFileWrite ) ); |
|
175 CleanupClosePushL( stream ); |
|
176 // Convert and export to vcard |
|
177 aContactConverter.ConvertAndExportContactL( aContactItem, stream ); |
|
178 |
|
179 stream.CommitL(); |
|
180 CleanupStack::PopAndDestroy( &stream ); |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // CPbkxRclvCardSender::DestroyTempFileL |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 void CPbkxRclvCardSender::DestroyTempFileL() |
|
188 { |
|
189 FUNC_LOG; |
|
190 //<cmail> |
|
191 User::LeaveIfError( iEikEnv->FsSession().Delete( iTempFileName ) ); |
|
192 //<cmail> |
|
193 } |
|
194 |
|
195 // --------------------------------------------------------------------------- |
|
196 // CPbkxRclvCardSender::CreateRichTextFromFileLC |
|
197 // --------------------------------------------------------------------------- |
|
198 // |
|
199 CRichText* CPbkxRclvCardSender::CreateRichTextFromFileLC() |
|
200 { |
|
201 FUNC_LOG; |
|
202 |
|
203 // Common allocation granularity and buffer size for rich text and |
|
204 // file reading |
|
205 const TInt KBufSize = CEditableText::EDefaultTextGranularity; |
|
206 |
|
207 // Create a rich text object with default formatting |
|
208 CRichText* richText = CRichText::NewL( |
|
209 iEikEnv->SystemParaFormatLayerL(), |
|
210 iEikEnv->SystemCharFormatLayerL(), |
|
211 CEditableText::ESegmentedStorage, |
|
212 KBufSize // Allocation granularity |
|
213 ); |
|
214 CleanupStack::PushL( richText ); |
|
215 |
|
216 // Open the file for reading |
|
217 RFile file; |
|
218 //<cmail> take away double line break |
|
219 User::LeaveIfError( file.Open( iEikEnv->FsSession(), |
|
220 iTempFileName, //<cmail> |
|
221 EFileRead | EFileStream | EFileShareReadersOnly ) ); |
|
222 //</cmail> |
|
223 CleanupClosePushL( file ); |
|
224 |
|
225 // Create two buffers: 8-bit for reading from file and 16-bit for |
|
226 // converting to 16-bit format |
|
227 HBufC8* buf8 = HBufC8::NewLC( KBufSize ); |
|
228 TPtr8 ptr8 = buf8->Des(); |
|
229 HBufC16* buf16 = HBufC16::NewLC( ptr8.MaxLength() ); |
|
230 TPtr16 ptr16 = buf16->Des(); |
|
231 |
|
232 // Read, convert and append to rich text until the file ends |
|
233 User::LeaveIfError( file.Read( ptr8 ) ); |
|
234 while ( ptr8.Length() > 0 ) |
|
235 { |
|
236 ptr16.Copy( ptr8 ); |
|
237 richText->InsertL( richText->DocumentLength(), ptr16 ); |
|
238 User::LeaveIfError( file.Read( ptr8 ) ); |
|
239 } |
|
240 |
|
241 // Cleanup and return |
|
242 CleanupStack::PopAndDestroy( buf16 ); |
|
243 CleanupStack::PopAndDestroy( buf8 ); |
|
244 CleanupStack::PopAndDestroy( &file ); |
|
245 return richText; |
|
246 } |
|
247 |
|
248 // --------------------------------------------------------------------------- |
|
249 // CPbkxRclvCardSender::CreateFilterL |
|
250 // --------------------------------------------------------------------------- |
|
251 // |
|
252 void CPbkxRclvCardSender::CreateFilterL() |
|
253 { |
|
254 FUNC_LOG; |
|
255 if ( iFilter == NULL ) |
|
256 { |
|
257 iFilter = new ( ELeave ) CArrayFixFlat<TUid>( KArrayGranularity ); |
|
258 } |
|
259 else |
|
260 { |
|
261 iFilter->Reset(); |
|
262 } |
|
263 |
|
264 const TUid KPostcardMtmUid = { KSenduiMtmPostcardUidValue }; |
|
265 |
|
266 iFilter->AppendL( KPostcardMtmUid ); // hide postcard |
|
267 iFilter->AppendL( KSenduiMtmAudioMessageUid ); // hide audio message |
|
268 |
|
269 // Check must we disable SMS menuitem |
|
270 if ( !iSendUi->CanSendBioMessage( KMsgBioUidVCard ) ) |
|
271 { |
|
272 iFilter->AppendL( KSenduiMtmSmsUid ); // hide SMS |
|
273 } |
|
274 |
|
275 // Hide MMS if not supported |
|
276 if ( !FeatureManager::FeatureSupported( KFeatureIdMMS ) ) |
|
277 { |
|
278 iFilter->AppendL(KSenduiMtmMmsUid); |
|
279 } |
|
280 |
|
281 // Hide Email if not supported |
|
282 if ( !FeatureManager::FeatureSupported( KFeatureIdEmailUi ) ) |
|
283 { |
|
284 iFilter->AppendL( KSenduiMtmSmtpUid ); |
|
285 iFilter->AppendL( KSenduiMtmImap4Uid ); |
|
286 iFilter->AppendL( KSenduiMtmPop3Uid ); |
|
287 iFilter->AppendL( KSenduiMtmSyncMLEmailUid ); |
|
288 } |
|
289 |
|
290 } |
|
291 //<cmail> hard coded paths removed |
|
292 // --------------------------------------------------------------------------- |
|
293 // CPbkxRclvCardSender::GetTemporaryFileName |
|
294 // --------------------------------------------------------------------------- |
|
295 // |
|
296 TInt CPbkxRclvCardSender::GetTemporaryFileNameL( TFileName& aFileName, CPbkContactItem& aContactItem ) |
|
297 { |
|
298 TFileName KPath; |
|
299 RFs fsSession; |
|
300 TInt result = fsSession.Connect(); |
|
301 if( result==KErrNone ) |
|
302 { |
|
303 fsSession.PrivatePath( KPath ); |
|
304 TFindFile findFile( fsSession ); |
|
305 aFileName = KPath; |
|
306 result = findFile.FindByDir( KPath, KNullDesC ); |
|
307 if (result != KErrNone ) //create path if doesn't exists |
|
308 { |
|
309 fsSession.CreatePrivatePath( TDriveUnit(PathInfo::PhoneMemoryRootPath() ) ); |
|
310 result = findFile.FindByDir( KPath, KNullDesC ); |
|
311 } |
|
312 aFileName = findFile.File(); |
|
313 aFileName.Append( *aContactItem.GetContactTitleL() ); // getting name from contact |
|
314 aFileName.Append( KVcardExtension ); // postfix extension |
|
315 fsSession.Close(); |
|
316 } |
|
317 return result; |
|
318 } |
|
319 //</cmail> |
|
320 |
|