|
1 // Copyright (c) 1998-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 // BIOCMTM.CPP |
|
15 // |
|
16 |
|
17 #include "BIOCMTM.H" |
|
18 #include "BIOSCMDS.H" |
|
19 |
|
20 #include <biouids.h> |
|
21 #include <f32file.h> |
|
22 #include "regpsdll.h" // Parser Registry - used to load the parser |
|
23 #include <biodb.h> |
|
24 #include "BIOOP.H" |
|
25 #include <msvstd.h> |
|
26 |
|
27 #include <mtmuids.h> |
|
28 #include <msvreg.h> |
|
29 #include <mtmdef.h> |
|
30 #include <msvftext.h> |
|
31 |
|
32 #include <txtrich.h> |
|
33 #include <txtfmlyr.h> |
|
34 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
35 #include "tmsvbioinfo.h" |
|
36 #include <biomessageuids.h> |
|
37 #include <bifchangeobserver.h> |
|
38 #include <mtmuidsdef.hrh> |
|
39 #endif |
|
40 |
|
41 #include <msvenhancesearchsortutil.h> |
|
42 |
|
43 |
|
44 EXPORT_C CBIOClientMtm* CBIOClientMtm::NewL(CRegisteredMtmDll& aRegisteredMtmDll, CMsvSession& aSession) |
|
45 /** Allocates and constructs a new BIO client MTM object. |
|
46 |
|
47 @param aRegisteredMtmDll Registration data for the MTM DLL |
|
48 @param aSession The CMsvSession of the client requesting the object |
|
49 @return New BIO client MTM object */ |
|
50 { |
|
51 CBIOClientMtm* self=new(ELeave) CBIOClientMtm(aRegisteredMtmDll, aSession); |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(); |
|
54 CleanupStack::Pop(self); |
|
55 return self; |
|
56 } |
|
57 |
|
58 CBIOClientMtm::~CBIOClientMtm() |
|
59 /** Destructor. */ |
|
60 { |
|
61 delete iBioDatabase; |
|
62 iFs.Close(); |
|
63 } |
|
64 |
|
65 void CBIOClientMtm::ConstructL() |
|
66 { |
|
67 User::LeaveIfError(iFs.Connect()); |
|
68 // construct a Bio database |
|
69 iBioDatabase = CBIODatabase::NewL(iFs); |
|
70 } |
|
71 |
|
72 void CBIOClientMtm::HandleEntryEvent(TMsvEntryEvent /*aEvent*/, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/) |
|
73 /** Does nothing. |
|
74 |
|
75 @param aEvent Unused |
|
76 @param aArg1 Unused |
|
77 @param aArg2 Unused |
|
78 @param aArg3 Unused */ |
|
79 { |
|
80 } |
|
81 |
|
82 void CBIOClientMtm::SaveMessageL() |
|
83 /** Commits cached changes to the current context's body text to storage. */ |
|
84 { |
|
85 CMsvStore* store = iMsvEntry->EditStoreL(); |
|
86 CleanupStack::PushL(store); |
|
87 StoreBodyL(*store); |
|
88 store->CommitL(); |
|
89 CleanupStack::PopAndDestroy(); |
|
90 } |
|
91 |
|
92 void CBIOClientMtm::LoadMessageL() |
|
93 /** Loads the current context's message body from storage. */ |
|
94 { |
|
95 CMsvStore* store = iMsvEntry->ReadStoreL(); |
|
96 CleanupStack::PushL(store); |
|
97 |
|
98 |
|
99 // Get a reference to TMsvEnhanceSearchSortUtil instance set by CMsvSearchsortOpOnHeaderBody class |
|
100 // If advanced search and sort is being performed than do not load the body here |
|
101 // For API's other than CMsvSearchsortOpOnHeaderBody-> FindInHeaderBodyL(), a call to LoadMessageL() |
|
102 // loads the body. |
|
103 TMsvEnhanceSearchSortUtil* searchsortutil = (TMsvEnhanceSearchSortUtil*)(GetExtensionData()); |
|
104 |
|
105 |
|
106 if ( searchsortutil == NULL ) |
|
107 { |
|
108 if (store->HasBodyTextL()) |
|
109 { |
|
110 RestoreBodyL(*store); |
|
111 } |
|
112 } |
|
113 |
|
114 CleanupStack::PopAndDestroy(); |
|
115 } |
|
116 |
|
117 CMsvOperation* CBIOClientMtm::ReplyL (TMsvId /*aDestination*/, TMsvPartList /*aPartlist*/, TRequestStatus& /*aCompletionStatus*/) |
|
118 /** Leaves with KErrNotSupported. |
|
119 |
|
120 @param aDestination Unused |
|
121 @param aPartlist Unused |
|
122 @param aCompletionStatus Unused |
|
123 @return Unused */ |
|
124 { |
|
125 User::Leave(KErrNotSupported); |
|
126 return NULL; |
|
127 } |
|
128 |
|
129 CMsvOperation* CBIOClientMtm::ForwardL(TMsvId /*aDestination*/, TMsvPartList /*aPartList*/, TRequestStatus& /*aCompletionStatus*/) |
|
130 /** Leaves with KErrNotSupported. |
|
131 |
|
132 @param aDestination Unused |
|
133 @param aPartList Unused |
|
134 @param aCompletionStatus Unused |
|
135 @return Unused */ |
|
136 { |
|
137 User::Leave(KErrNotSupported); |
|
138 return NULL; |
|
139 } |
|
140 |
|
141 TMsvPartList CBIOClientMtm::ValidateMessage(TMsvPartList /*aPartList*/) |
|
142 /** Does nothing. |
|
143 |
|
144 @param aPartList Unused |
|
145 @return Always 0 */ |
|
146 { |
|
147 return 0; |
|
148 } |
|
149 |
|
150 TMsvPartList CBIOClientMtm::Find(const TDesC& aTextToFind, TMsvPartList aPartList) |
|
151 /** Searches the specified message part(s) for the plain-text version of the text |
|
152 to be found. |
|
153 |
|
154 Supported messages parts are KMsvMessagePartBody, KMsvMessagePartOriginator, |
|
155 and KMsvMessagePartDescription. |
|
156 |
|
157 @param aTextToFind The plain-text version of the text to be found. |
|
158 @param aPartList Indicates the message parts which should be searched. |
|
159 @return 0, if the text was not found, or searching is unsupported. If the text |
|
160 was found, a bitmask of the TMsvPartList IDs for each part in which the text |
|
161 was present. */ |
|
162 { |
|
163 TMsvPartList retList=KMsvMessagePartNone; |
|
164 |
|
165 // Enhance search and sort |
|
166 // The setting variables are accessed by getting an instance to TMsvEnhanceSearchSortUtil class |
|
167 // This is accessed here by using GetExtensionData() defined in CBaseMtm which refers |
|
168 // to iExtensionData member variable |
|
169 |
|
170 TMsvEnhanceSearchSortUtil* searchsortutil = (TMsvEnhanceSearchSortUtil*)(GetExtensionData()); |
|
171 |
|
172 // For callees other than CMsvSearchsortOpOnHeaderBody class, searchsortutil pointer will be NULL |
|
173 if(searchsortutil != NULL) |
|
174 { |
|
175 // Get the setting values from TMsvEnhanceSearchSortUtil iPartList variable |
|
176 TInt32 searchsortsetting=searchsortutil->GetSearchSortSetting(); |
|
177 |
|
178 if (aPartList & KMsvMessagePartFrom) // From search |
|
179 { |
|
180 TRAPD(ret,FindInOriginatorL(aTextToFind,aPartList,retList)); |
|
181 if (ret != KErrNone) |
|
182 { |
|
183 User::LeaveIfError(ret); |
|
184 } |
|
185 } |
|
186 else if (aPartList & KMsvMessagePartSubject) // Subject search |
|
187 { |
|
188 TRAPD(ret,FindInDescriptionL(aTextToFind,aPartList,retList)); |
|
189 if (ret != KErrNone) |
|
190 { |
|
191 User::LeaveIfError(ret); |
|
192 } |
|
193 } |
|
194 // Load the body if it wasnt previously loaded |
|
195 else if ((aPartList & KMsvMessagePartBody) && !(searchsortsetting & EMessagePartBodyLoaded)) |
|
196 { |
|
197 // Load the message body |
|
198 CMsvStore* store = iMsvEntry->ReadStoreL(); |
|
199 CleanupStack::PushL(store); |
|
200 if (store->HasBodyTextL()) |
|
201 { |
|
202 RestoreBodyL(*store); |
|
203 } |
|
204 |
|
205 // The message body is loaded.Set the setting variable to specify that the body is loaded |
|
206 // If the next search is also on body, than it wont be loaded next time. |
|
207 |
|
208 searchsortutil->SetSearchSortSetting(EMessagePartBodyLoaded); |
|
209 |
|
210 TRAPD(ret,FindInBodyL(aTextToFind,aPartList,retList)); // Body search |
|
211 |
|
212 if (ret != KErrNone) |
|
213 { |
|
214 User::LeaveIfError(ret); |
|
215 } |
|
216 CleanupStack::PopAndDestroy(); // store |
|
217 } |
|
218 // Copying the Sort data for advanced search and sort. |
|
219 // This is done by setting the iExtensionData member variable of CBaseMtm class point |
|
220 // to the field being sorted |
|
221 if ((searchsortsetting & EMessagePartSort ) || ((searchsortsetting & EMessagePartSearchSort) && (searchsortsetting & EMessagePartLastQueryOption) && (retList))) |
|
222 { |
|
223 if(searchsortsetting & EMessagePartFromSort) |
|
224 { |
|
225 SetExtensionData((TAny*)&iMsvEntry->Entry().iDetails); |
|
226 } |
|
227 else if(searchsortsetting & EMessagePartSubjectSort) |
|
228 { |
|
229 SetExtensionData((TAny*)&iMsvEntry->Entry().iDescription); |
|
230 } |
|
231 else |
|
232 { |
|
233 searchsortutil->SetSearchSortSetting(EMessagePartInvalidSortField); |
|
234 } |
|
235 } |
|
236 } |
|
237 else |
|
238 { |
|
239 |
|
240 //Normal search. Implementation prior to PREQ1667 (Advanced search and sort on message store) |
|
241 if (aPartList&KMsvMessagePartBody) |
|
242 { |
|
243 TRAPD(ret,FindInBodyL(aTextToFind,aPartList,retList)); |
|
244 if (ret != KErrNone) |
|
245 { |
|
246 User::LeaveIfError(ret); |
|
247 } |
|
248 } |
|
249 else if (aPartList&KMsvMessagePartOriginator) |
|
250 { |
|
251 TRAPD(ret,FindInOriginatorL(aTextToFind,aPartList,retList)); |
|
252 if (ret != KErrNone) |
|
253 { |
|
254 User::LeaveIfError(ret); |
|
255 } |
|
256 } |
|
257 else if (aPartList&KMsvMessagePartDescription) |
|
258 { |
|
259 TRAPD(ret,FindInDescriptionL(aTextToFind,aPartList,retList)); |
|
260 if (ret != KErrNone) |
|
261 { |
|
262 User::LeaveIfError(ret); |
|
263 } |
|
264 } |
|
265 } |
|
266 return retList; |
|
267 } |
|
268 |
|
269 void CBIOClientMtm::FindInDescriptionL(const TDesC& aTextToFind, TMsvPartList aPartList,TMsvPartList& aFoundList) |
|
270 { |
|
271 CMsvFindText* text=CMsvFindText::NewL(); |
|
272 CleanupStack::PushL(text); |
|
273 |
|
274 if (text->FindTextL(aTextToFind,iMsvEntry->Entry().iDescription,aPartList)) |
|
275 aFoundList|=KMsvMessagePartDescription; |
|
276 |
|
277 CleanupStack::PopAndDestroy();// text |
|
278 } |
|
279 |
|
280 void CBIOClientMtm::FindInOriginatorL(const TDesC& aTextToFind, TMsvPartList aPartList,TMsvPartList& aFoundList) |
|
281 { |
|
282 CMsvFindText* text=CMsvFindText::NewL(); |
|
283 CleanupStack::PushL(text); |
|
284 |
|
285 if (text->FindTextL(aTextToFind,iMsvEntry->Entry().iDetails,aPartList)) |
|
286 aFoundList|=KMsvMessagePartBody; |
|
287 |
|
288 CleanupStack::PopAndDestroy();// text |
|
289 } |
|
290 |
|
291 void CBIOClientMtm::FindInBodyL(const TDesC& aTextToFind, TMsvPartList aPartList,TMsvPartList& aFoundList) |
|
292 { |
|
293 CMsvFindText* text=CMsvFindText::NewL(); |
|
294 CleanupStack::PushL(text); |
|
295 |
|
296 if (text->FindRichTextL(aTextToFind,Body(),aPartList)) |
|
297 aFoundList|=KMsvMessagePartBody; |
|
298 |
|
299 CleanupStack::PopAndDestroy();// text |
|
300 } |
|
301 |
|
302 void CBIOClientMtm::AddAddresseeL(const TDesC& /*aRealAddress*/) |
|
303 /** Leaves with KErrNotSupported. |
|
304 |
|
305 @param aRealAddress Unused */ |
|
306 { |
|
307 User::Leave(KErrNotSupported); |
|
308 } |
|
309 |
|
310 void CBIOClientMtm::AddAddresseeL(const TDesC& /*aRealAddress*/, const TDesC& /*aAlias*/) |
|
311 /** Leaves with KErrNotSupported. |
|
312 |
|
313 @param aRealAddress Unused |
|
314 @param aAlias Unused */ |
|
315 { |
|
316 User::Leave(KErrNotSupported); |
|
317 } |
|
318 |
|
319 void CBIOClientMtm::RemoveAddressee(TInt /*aIndex*/) |
|
320 /** Does nothing. |
|
321 |
|
322 @param aIndex Unused */ |
|
323 { |
|
324 } |
|
325 |
|
326 void CBIOClientMtm::ContextEntrySwitched() |
|
327 { |
|
328 } |
|
329 |
|
330 void CBIOClientMtm::InvokeSyncFunctionL(TInt /*aFunctionId*/,const CMsvEntrySelection& /*aSelection*/, TDes8& /*aParameter*/) |
|
331 /** Leaves with KErrNotSupported. |
|
332 |
|
333 @param aFunctionId Unused |
|
334 @param aSelection Unused |
|
335 @param aParameter Unused */ |
|
336 { |
|
337 User::Leave(KErrNotSupported); |
|
338 } |
|
339 |
|
340 CMsvOperation* CBIOClientMtm::InvokeAsyncFunctionL(TInt aFunctionId,const CMsvEntrySelection& aSelection, TDes8& /*aParameter*/, TRequestStatus& aCompletionStatus) |
|
341 /** Requests a BIO message to be parsed or processed. |
|
342 |
|
343 The behaviour resulting from the request is specific to the BIO message type. |
|
344 Typically, parsing causes an interpretation of the raw message body, and storage |
|
345 of the results. Processing causes some system action to take place according |
|
346 to the instructions in the message. |
|
347 |
|
348 @param aFunctionId ID of the requested operation: this must be a TBiosCmds |
|
349 value. |
|
350 @param aSelection Message entry to parse or process. |
|
351 @param aParameter Unused |
|
352 @param aCompletionStatus The request status to be completed when the operation |
|
353 has finished |
|
354 @return If successful, this is an asynchronously completing operation. If failed, |
|
355 this is a completed operation, with status set to the relevant error code. */ |
|
356 { |
|
357 if (aFunctionId != KBiosMtmParse && |
|
358 aFunctionId != KBiosMtmParseThenProcess && |
|
359 aFunctionId != KBiosMtmProcess) |
|
360 User::Leave(KErrNotSupported); |
|
361 |
|
362 __ASSERT_DEBUG(aSelection.Count()>=1, User::Panic(_L("BIOC"), KBIOMessageNotFound)); |
|
363 // Messaging API V2 |
|
364 CBIOOperation* parseOp = CBIOOperation::NewL(iFs, Session(), iBioDatabase, aCompletionStatus); |
|
365 parseOp->StartCommand(aSelection, aFunctionId, aCompletionStatus); |
|
366 return parseOp; |
|
367 } |
|
368 |
|
369 // --- RTTI functions --- |
|
370 TInt CBIOClientMtm::QueryCapability(TUid aCapability, TInt& aResponse) |
|
371 /** Queries if the MTM supports a particular capability, specified by a UID. |
|
372 |
|
373 It supports KUidMtmQueryMaxBodySize, KUidMtmQueryMaxTotalMsgSize, KUidMsvMtmQueryEditorUid, |
|
374 KUidMtmQuerySupportedBody, and KUidMtmQueryCanReceiveMsg. |
|
375 |
|
376 @param aCapability UID of capability to be queried |
|
377 @param aResponse Response value. The format of the response varies according |
|
378 to the capability. |
|
379 @return KErrNone: aCapability is a recognised value and a response is returned |
|
380 KErrNotSupported: aCapability is not a recognised value */ |
|
381 { |
|
382 TInt error = KErrNone; |
|
383 // Supported |
|
384 switch (aCapability.iUid) |
|
385 { |
|
386 case KUidMtmQueryMaxBodySizeValue: |
|
387 case KUidMtmQueryMaxTotalMsgSizeValue: |
|
388 aResponse = KMaxTInt; |
|
389 break; |
|
390 case KUidMsvMtmQueryEditorUidValue: |
|
391 aResponse = KUidBIOMessageViewerApp.iUid; |
|
392 break; |
|
393 case KUidMtmQuerySupportedBodyValue: |
|
394 aResponse = KMtm7BitBody + KMtm8BitBody + KMtm16BitBody + KMtmBinaryBody; |
|
395 break; |
|
396 case KUidMtmQueryCanReceiveMsgValue: |
|
397 break; |
|
398 // All others - Not Supported: |
|
399 default: |
|
400 error = KErrNotSupported; |
|
401 } |
|
402 return error; |
|
403 } |
|
404 |
|
405 |
|
406 // |
|
407 // constructor |
|
408 // |
|
409 CBIOClientMtm::CBIOClientMtm(CRegisteredMtmDll& aRegisteredMtmDll, CMsvSession& aSession) |
|
410 : CBaseMtm(aRegisteredMtmDll, aSession) |
|
411 { |
|
412 } |
|
413 |