|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // csendastestclientmtm.cpp |
|
15 // |
|
16 #include "csendastestclientmtm.h" |
|
17 |
|
18 #include <msvids.h> |
|
19 #include <msvuids.h> |
|
20 #include <txtrich.h> |
|
21 |
|
22 #include "csendastestaddress.h" |
|
23 #include "csendastestsendoperation.h" |
|
24 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
25 #include "msvconsts.h" |
|
26 #endif |
|
27 |
|
28 const TInt KSendAsTestMtmMaxBodySize = 0x100; |
|
29 const TInt KSendAsTestMtmMaxMessageSize = 0x200; |
|
30 |
|
31 EXPORT_C CSendAsTestClientMtm* CSendAsTestClientMtm::NewL(CRegisteredMtmDll& aRegisteredMtmDll, CMsvSession& aSession) |
|
32 { |
|
33 CSendAsTestClientMtm* self = new (ELeave) CSendAsTestClientMtm(aRegisteredMtmDll, aSession); |
|
34 CleanupStack::PushL(self); |
|
35 self->ConstructL(); |
|
36 CleanupStack::Pop(self); |
|
37 return self; |
|
38 } |
|
39 |
|
40 CSendAsTestClientMtm::~CSendAsTestClientMtm() |
|
41 { |
|
42 delete iSendAsTestMessage; |
|
43 } |
|
44 |
|
45 CSendAsTestClientMtm::CSendAsTestClientMtm(CRegisteredMtmDll& aRegisteredMtmDll, CMsvSession& aSession) |
|
46 : CBaseMtm(aRegisteredMtmDll, aSession) |
|
47 { |
|
48 } |
|
49 |
|
50 void CSendAsTestClientMtm::ConstructL() |
|
51 { |
|
52 // Find the default service... |
|
53 TMsvSelectionOrdering ordering(KMsvNoGrouping, EMsvSortByNone, ETrue); |
|
54 CMsvEntry* entry = CMsvEntry::NewL(Session(), KMsvRootIndexEntryId, ordering); |
|
55 CleanupStack::PushL(entry); |
|
56 |
|
57 CMsvEntrySelection* sel = entry->ChildrenWithMtmL(KUidMsgTypeSendAsTest); |
|
58 CleanupStack::PushL(sel); |
|
59 if( sel->Count() == 0 ) |
|
60 { |
|
61 // There is no service - create it. |
|
62 TMsvEntry service; |
|
63 service.iMtm = KUidMsgTypeSendAsTest; |
|
64 service.iType = KUidMsvServiceEntry; |
|
65 service.SetReadOnly(EFalse); |
|
66 service.SetVisible(ETrue); |
|
67 |
|
68 entry->SetEntryL(KMsvRootIndexEntryId); |
|
69 entry->CreateL(service); |
|
70 |
|
71 iServiceId = service.Id(); |
|
72 } |
|
73 else |
|
74 { |
|
75 iServiceId = sel->At(0); |
|
76 } |
|
77 CleanupStack::PopAndDestroy(2, entry); // entry, sel |
|
78 |
|
79 // Switch the context - this will initialise various objects in the base. |
|
80 SwitchCurrentEntryL(KMsvRootIndexEntryId); |
|
81 |
|
82 iSendAsTestMessage = CSendAsTestMessage::NewL(); |
|
83 } |
|
84 |
|
85 void CSendAsTestClientMtm::DoAddAddresseeL(const TDesC& aAddress, const TDesC& aAlias, CSendAsTestMessage::TSendAsTestAddressType aType) |
|
86 { |
|
87 // Need to ensure that the message address list and the addressee list stay |
|
88 // in sync. First create the address object that will be added to the message |
|
89 // address list. |
|
90 CSendAsTestAddress* address = CSendAsTestAddress::NewL(); |
|
91 CleanupStack::PushL(address); |
|
92 address->SetAddressL(aAddress); |
|
93 address->SetAliasL(aAlias); |
|
94 address->SetAddressType(aType); |
|
95 |
|
96 // Add the address info to the addressee list - if this fails then ok as |
|
97 // message list has not been added to. |
|
98 AddToAddresseeListL(aAddress, aAlias); |
|
99 |
|
100 // Now add to the message address list... |
|
101 RPointerArray<CSendAsTestAddress>& array = iSendAsTestMessage->Addresses(); |
|
102 TInt err = array.Append(address); |
|
103 if( err != KErrNone ) |
|
104 { |
|
105 // Could not add address to the message address list - remove the last |
|
106 // added address from the addressee list. |
|
107 iAddresseeList->Delete(iAddresseeList->Count()-1); |
|
108 User::Leave(err); |
|
109 } |
|
110 else |
|
111 { |
|
112 // The address was successfully added - pop off the cleanup stack. |
|
113 CleanupStack::Pop(address); |
|
114 } |
|
115 } |
|
116 |
|
117 void CSendAsTestClientMtm::AddToAddresseeListL(const TDesC& aAddress, const TDesC& aAlias) |
|
118 { |
|
119 // Append address to addressee list... |
|
120 if( aAlias.Length() > 0 ) |
|
121 { |
|
122 HBufC* buf = HBufC::NewLC(aAlias.Length() + aAddress.Length() + 3); |
|
123 TPtr ptr = buf->Des(); |
|
124 ptr.Copy(aAlias); |
|
125 ptr.Append(' '); |
|
126 ptr.Append('<'); |
|
127 ptr.Append(aAddress); |
|
128 ptr.Append('>'); |
|
129 iAddresseeList->AppendL(ptr); |
|
130 CleanupStack::PopAndDestroy(buf); |
|
131 } |
|
132 else |
|
133 { |
|
134 iAddresseeList->AppendL(aAddress); |
|
135 } |
|
136 } |
|
137 |
|
138 void CSendAsTestClientMtm::Reset() |
|
139 { |
|
140 // Reset the two address lists. |
|
141 if( iAddresseeList != NULL ) |
|
142 { |
|
143 iAddresseeList->Reset(); |
|
144 } |
|
145 if( iSendAsTestMessage != NULL ) |
|
146 { |
|
147 iSendAsTestMessage->Addresses().ResetAndDestroy(); |
|
148 } |
|
149 } |
|
150 |
|
151 /* |
|
152 * from CBaseMtm |
|
153 */ |
|
154 |
|
155 void CSendAsTestClientMtm::SaveMessageL() |
|
156 { |
|
157 __ASSERT_DEBUG( iMsvEntry != NULL, User::Invariant() ); |
|
158 |
|
159 CMsvStore* store = iMsvEntry->EditStoreL(); |
|
160 CleanupStack::PushL(store); |
|
161 |
|
162 switch( iMsvEntry->Entry().iType.iUid ) |
|
163 { |
|
164 case KUidMsvServiceEntryValue: |
|
165 case KUidMsvFolderEntryValue: |
|
166 break; |
|
167 case KUidMsvMessageEntryValue: |
|
168 { |
|
169 iSendAsTestMessage->StoreL(*store); |
|
170 StoreBodyL(*store); |
|
171 TMsvEntry entry(iMsvEntry->Entry()); |
|
172 if (iSendAsTestMessage->BioType() != KNullUid) |
|
173 { |
|
174 entry.iBioType = iSendAsTestMessage->BioType().iUid; |
|
175 } |
|
176 |
|
177 iMsvEntry->ChangeL(entry); |
|
178 |
|
179 } break; |
|
180 default: |
|
181 User::Invariant(); |
|
182 } |
|
183 store->CommitL(); |
|
184 |
|
185 // Set the iSize member of the TMsvEntry |
|
186 if( iMsvEntry->HasStoreL() ) |
|
187 { |
|
188 const TInt size = store->SizeL(); |
|
189 TMsvEntry entry(iMsvEntry->Entry()); |
|
190 if( entry.iSize != size ) |
|
191 { |
|
192 entry.iSize = size; |
|
193 iMsvEntry->ChangeL(entry); |
|
194 } |
|
195 } |
|
196 CleanupStack::PopAndDestroy(store); |
|
197 } |
|
198 |
|
199 void CSendAsTestClientMtm::LoadMessageL() |
|
200 { |
|
201 __ASSERT_DEBUG( iMsvEntry != NULL, User::Invariant() ); |
|
202 |
|
203 Reset(); |
|
204 Body().Reset(); |
|
205 |
|
206 CMsvStore* store = iMsvEntry->ReadStoreL(); |
|
207 CleanupStack::PushL(store); |
|
208 |
|
209 switch( iMsvEntry->Entry().iType.iUid ) |
|
210 { |
|
211 case KUidMsvServiceEntryValue: |
|
212 case KUidMsvFolderEntryValue: |
|
213 break; |
|
214 case KUidMsvMessageEntryValue: |
|
215 { |
|
216 CSendAsTestMessage* message = CSendAsTestMessage::NewL(); |
|
217 CleanupStack::PushL(message); |
|
218 |
|
219 // Restore the message from the store and populate the addressee list. |
|
220 message->RestoreL(*store); |
|
221 |
|
222 const RPointerArray<CSendAsTestAddress>& addresses = message->Addresses(); |
|
223 TInt count = addresses.Count(); |
|
224 |
|
225 for( TInt i=0; i<count; ++i ) |
|
226 { |
|
227 const CSendAsTestAddress& address = *addresses[i]; |
|
228 AddToAddresseeListL(address.Address(), address.Alias()); |
|
229 } |
|
230 |
|
231 store->RestoreBodyTextL(Body()); |
|
232 |
|
233 CleanupStack::Pop(message); |
|
234 delete iSendAsTestMessage; |
|
235 iSendAsTestMessage = message; |
|
236 } break; |
|
237 default: |
|
238 User::Invariant(); |
|
239 } |
|
240 CleanupStack::PopAndDestroy(store); |
|
241 } |
|
242 |
|
243 TMsvPartList CSendAsTestClientMtm::ValidateMessage(TMsvPartList /*aPartList*/) |
|
244 { |
|
245 TMsvPartList retList = 0; |
|
246 return retList; |
|
247 } |
|
248 |
|
249 TMsvPartList CSendAsTestClientMtm::Find(const TDesC& /*aTextToFind*/, TMsvPartList /*aPartList*/) |
|
250 { |
|
251 TMsvPartList retList = 0; |
|
252 return retList; |
|
253 } |
|
254 |
|
255 CMsvOperation* CSendAsTestClientMtm::ReplyL(TMsvId /*aDestination*/, TMsvPartList /*aPartlist*/, TRequestStatus& aCompletionStatus) |
|
256 { |
|
257 TMsvEntry entry = iMsvEntry->Entry(); |
|
258 TPckg<TMsvId> prog(entry.Id()); |
|
259 return CMsvCompletedOperation::NewL(Session(), KUidMsgTypeSendAsTest, prog, entry.iServiceId, aCompletionStatus, KErrNotSupported); |
|
260 } |
|
261 |
|
262 CMsvOperation* CSendAsTestClientMtm::ForwardL(TMsvId /*aDestination*/, TMsvPartList /*aPartList*/, TRequestStatus& aCompletionStatus) |
|
263 { |
|
264 TMsvEntry entry = iMsvEntry->Entry(); |
|
265 TPckg<TMsvId> prog(entry.Id()); |
|
266 return CMsvCompletedOperation::NewL(Session(), KUidMsgTypeSendAsTest, prog, entry.iServiceId, aCompletionStatus, KErrNotSupported); |
|
267 } |
|
268 |
|
269 void CSendAsTestClientMtm::AddAddresseeL(TMsvRecipientType aType, const TDesC& aRealAddress) |
|
270 { |
|
271 DoAddAddresseeL(aRealAddress, KNullDesC(), (CSendAsTestMessage::TSendAsTestAddressType)aType); |
|
272 } |
|
273 |
|
274 void CSendAsTestClientMtm::AddAddresseeL(TMsvRecipientType aType, const TDesC& aRealAddress, const TDesC& aAlias) |
|
275 { |
|
276 DoAddAddresseeL(aRealAddress, aAlias, (CSendAsTestMessage::TSendAsTestAddressType)aType); |
|
277 } |
|
278 |
|
279 void CSendAsTestClientMtm::AddAddresseeL(const TDesC& aRealAddress) |
|
280 { |
|
281 DoAddAddresseeL(aRealAddress, KNullDesC(), CSendAsTestMessage::ESendAsTestAddressTypeTo); |
|
282 } |
|
283 |
|
284 void CSendAsTestClientMtm::AddAddresseeL(const TDesC& aRealAddress, const TDesC& aAlias) |
|
285 { |
|
286 DoAddAddresseeL(aRealAddress, aAlias, CSendAsTestMessage::ESendAsTestAddressTypeTo); |
|
287 } |
|
288 |
|
289 void CSendAsTestClientMtm::RemoveAddressee(TInt aIndex) |
|
290 { |
|
291 __ASSERT_DEBUG( iSendAsTestMessage->Addresses().Count() == iAddresseeList->Count(), User::Invariant() ); |
|
292 |
|
293 // Remove the address from the addressee list and message address list. |
|
294 iAddresseeList->Delete(aIndex); |
|
295 iSendAsTestMessage->Addresses().Remove(aIndex); |
|
296 } |
|
297 |
|
298 void CSendAsTestClientMtm::SetSubjectL(const TDesC& aSubject) |
|
299 { |
|
300 iSendAsTestMessage->SetSubjectL(aSubject); |
|
301 } |
|
302 |
|
303 void CSendAsTestClientMtm::BioTypeChangedL(TUid aBioTypeUid) |
|
304 { |
|
305 iSendAsTestMessage->SetBioTypeL(aBioTypeUid); |
|
306 } |
|
307 |
|
308 TInt CSendAsTestClientMtm::QueryCapability(TUid aCapability, TInt& aResponse) |
|
309 { |
|
310 TInt error = KErrNone; |
|
311 aResponse = ETrue; |
|
312 switch( aCapability.iUid ) |
|
313 { |
|
314 case KUidMtmQueryMaxBodySizeValue: |
|
315 { |
|
316 aResponse = KSendAsTestMtmMaxBodySize; |
|
317 } break; |
|
318 case KUidMtmQueryMaxTotalMsgSizeValue: |
|
319 { |
|
320 aResponse = KSendAsTestMtmMaxMessageSize; |
|
321 } break; |
|
322 case KUidMtmQuerySupportedBodyValue: |
|
323 { |
|
324 aResponse = KMtm7BitBody + KMtm8BitBody + KMtm16BitBody; |
|
325 break; |
|
326 } |
|
327 case KUidMtmQueryCanSendMsgValue: |
|
328 case KUidMtmQuerySendAsMessageSendSupportValue: |
|
329 case KUidMtmQuerySupportAttachmentsValue: |
|
330 case KUidMtmQuerySupportSubjectValue: |
|
331 break; |
|
332 case KUidMtmQueryMaxRecipientCountValue: |
|
333 { |
|
334 aResponse = KErrNotFound; // not limited |
|
335 } break; |
|
336 case KUidMtmQueryCanReceiveMsgValue: |
|
337 case KUidMtmQuerySupportsBioMsgValue: |
|
338 case KUidMtmQuerySupportsSchedulingValue: |
|
339 case KUidMsvMtmQueryEditorUidValue: |
|
340 case KUidMtmQueryOffLineAllowedValue: |
|
341 case KUidMtmQuerySendAsRequiresRenderedImageValue: |
|
342 case KUidMtmQuerySendAsRenderingUidValue: |
|
343 case KUidMtmQuerySupportsFolderValue: |
|
344 case KUidMtmQuerySupportsRecipientTypeValue: |
|
345 default: |
|
346 error = KErrNotSupported; |
|
347 break; |
|
348 } |
|
349 return error; |
|
350 } |
|
351 |
|
352 void CSendAsTestClientMtm::InvokeSyncFunctionL(TInt /*FunctionId*/, const CMsvEntrySelection& /*aSelection*/, TDes8& /*aParameter*/) |
|
353 { |
|
354 |
|
355 User::Invariant(); |
|
356 } |
|
357 |
|
358 CMsvOperation* CSendAsTestClientMtm::InvokeAsyncFunctionL(TInt aFunctionId,const CMsvEntrySelection& aSelection, TDes8& aParameter, TRequestStatus& aCompletionStatus) |
|
359 { |
|
360 CMsvOperation* op = NULL; |
|
361 |
|
362 switch( aFunctionId ) |
|
363 { |
|
364 case KMTMStandardFunctionsSendMessage: |
|
365 { |
|
366 // perform a regular send with standardised progress information for SendAs2 |
|
367 op = CSendAsTestSendOperation::NewL(Session(), aSelection, aParameter, aCompletionStatus); |
|
368 } break; |
|
369 default: |
|
370 op = Session().TransferCommandL(aSelection,aFunctionId,(TDesC8&)aParameter, aCompletionStatus); |
|
371 break; |
|
372 }; |
|
373 return op; |
|
374 } |
|
375 |
|
376 TMsvId CSendAsTestClientMtm::DefaultServiceL() const |
|
377 { |
|
378 return iServiceId; |
|
379 } |
|
380 |
|
381 void CSendAsTestClientMtm::ContextEntrySwitched() |
|
382 { |
|
383 Reset(); |
|
384 } |
|
385 |
|
386 /* |
|
387 * from MMsvEntryObserver |
|
388 */ |
|
389 |
|
390 void CSendAsTestClientMtm::HandleEntryEvent(TMsvEntryEvent /*aEvent*/, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/) |
|
391 { |
|
392 } |