author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 18 Jan 2010 21:02:57 +0200 | |
changeset 27 | 02682e02e51f |
parent 23 | 50974a8b132e |
permissions | -rw-r--r-- |
5 | 1 |
/* |
2 |
* Copyright (c) 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 the License "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: Interface to messaging provider |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
#include <e32base.h> |
|
20 |
#include <msvstd.h> |
|
21 |
#include <msvapi.h> |
|
22 |
#include <msvids.h> |
|
23
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
10
diff
changeset
|
23 |
#include <SendUiConsts.h> |
5 | 24 |
|
25 |
#include "messageheader.h" |
|
26 |
#include "messagingservice.h" |
|
27 |
#include "messagenotify.h" |
|
28 |
#include "sendmessage.h" |
|
29 |
#include "accessfolder.h" |
|
30 |
#include "messagedetail.h" |
|
31 |
#include "changestatus.h" |
|
32 |
||
33 |
||
34 |
#ifdef __WINSCW__ |
|
35 |
#define KFolderId KMsvDraftEntryId; |
|
36 |
#else |
|
37 |
#define KFolderId KMsvGlobalInBoxIndexEntryId; |
|
38 |
#endif |
|
39 |
||
40 |
||
41 |
// --------------------------------------------------------------------------- |
|
42 |
// Two-phased constructor. |
|
43 |
// --------------------------------------------------------------------------- |
|
44 |
// |
|
45 |
EXPORT_C CMessagingService* CMessagingService::NewL() |
|
46 |
{ |
|
47 |
CMessagingService* self = new (ELeave) CMessagingService; |
|
48 |
CleanupStack::PushL( self ); |
|
49 |
self->ConstructL(); |
|
50 |
CleanupStack::Pop( self ); |
|
51 |
return self; |
|
52 |
} |
|
53 |
||
54 |
// --------------------------------------------------------------------------- |
|
55 |
// Destructor. |
|
56 |
// --------------------------------------------------------------------------- |
|
57 |
// |
|
58 |
CMessagingService::~CMessagingService() |
|
59 |
{ |
|
60 |
DeleteAsyncObjects();//deletes all Asychronous objects |
|
61 |
iAsyncObjArray.Reset(); |
|
62 |
delete iMsgServerSession; |
|
63 |
delete iSessionObserver; |
|
64 |
} |
|
65 |
||
66 |
// --------------------------------------------------------------------------- |
|
67 |
// Constructor. |
|
68 |
// --------------------------------------------------------------------------- |
|
69 |
// |
|
70 |
CMessagingService::CMessagingService() |
|
71 |
{ |
|
72 |
} |
|
73 |
||
74 |
// --------------------------------------------------------------------------- |
|
75 |
// Constructor. |
|
76 |
// --------------------------------------------------------------------------- |
|
77 |
// |
|
78 |
void CMessagingService::ConstructL() |
|
79 |
{ |
|
80 |
iSessionObserver = CMessageObserver::NewL(); |
|
81 |
||
82 |
iMsgServerSession = CMsvSession::OpenSyncL( *iSessionObserver ); |
|
83 |
||
84 |
((CMessageObserver*)iSessionObserver)->SetSession( iMsgServerSession ); |
|
85 |
} |
|
86 |
||
87 |
// --------------------------------------------------------------------------- |
|
88 |
// Sends Message |
|
89 |
// --------------------------------------------------------------------------- |
|
90 |
// |
|
91 |
EXPORT_C void CMessagingService::SendMessageL( CSendMessageParams* aMessageParam, |
|
92 |
CMsgCallbackBase* aCallback ) |
|
93 |
{ |
|
94 |
CMessageDetailInfo* templateDetail = NULL; |
|
95 |
||
96 |
if ( aMessageParam->TemplateId() > 0 ) |
|
97 |
{ |
|
98 |
CMessageDetail* detailObj = NULL; |
|
99 |
||
10
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
100 |
CMsvEntry * messageEntry = iMsgServerSession->GetEntryL( aMessageParam->TemplateId() ); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
101 |
|
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
102 |
CleanupStack::PushL(messageEntry); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
103 |
|
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
104 |
if ( aMessageParam->MessageType() == KSenduiMtmSmsUid && |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
105 |
messageEntry->Entry().iMtm == KSenduiMtmMmsUid ) |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
106 |
{ |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
107 |
User::Leave( KErrNotSupported ); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
108 |
} |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
109 |
|
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
110 |
CleanupStack::PopAndDestroy(messageEntry); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
111 |
|
5 | 112 |
detailObj = CMessageDetail::NewL( *iMsgServerSession ); |
113 |
||
114 |
CleanupStack::PushL( detailObj ); |
|
115 |
||
116 |
detailObj->GetMessageDetailL( aMessageParam->TemplateId(), templateDetail ); |
|
117 |
||
118 |
CleanupStack::PopAndDestroy( detailObj ); |
|
119 |
} |
|
120 |
else if ( aMessageParam->TemplateId() < 0 ) |
|
121 |
{ |
|
122 |
User::Leave( KErrNotSupported ); |
|
123 |
} |
|
124 |
||
125 |
||
126 |
CSendMessage* sendMessageObj = CSendMessage::NewL( *iMsgServerSession ); |
|
127 |
||
128 |
CleanupStack::PushL( sendMessageObj ); |
|
129 |
||
130 |
// aCallback, templateDetail ownership passes to CSendMessage |
|
131 |
sendMessageObj->SetInputParamsL( aMessageParam, templateDetail, aCallback, this ); |
|
132 |
||
133 |
if ( aCallback ) |
|
134 |
{ |
|
135 |
AddAsyncObjL( aCallback->iTransactionId, sendMessageObj ); |
|
136 |
} |
|
137 |
||
138 |
sendMessageObj->SendMessageL(); |
|
139 |
||
140 |
CleanupStack::Pop( sendMessageObj ); |
|
141 |
||
142 |
if ( !aCallback ) |
|
143 |
delete sendMessageObj; |
|
144 |
} |
|
145 |
||
146 |
// --------------------------------------------------------------------------- |
|
147 |
// Deletes Message |
|
148 |
// --------------------------------------------------------------------------- |
|
149 |
// |
|
150 |
EXPORT_C void CMessagingService::DeleteMessageL( const TMsvId aMessageId, |
|
151 |
CMsgCallbackBase* /*aCallback*/ ) |
|
152 |
{ |
|
153 |
CMessageChangeStatus* obj = NULL; |
|
154 |
||
155 |
obj = CMessageChangeStatus::NewL( *iMsgServerSession ); |
|
156 |
||
157 |
CleanupStack::PushL( obj ); |
|
158 |
||
159 |
obj->DeleteMessageL( aMessageId ); |
|
160 |
||
161 |
CleanupStack::PopAndDestroy( obj ); |
|
162 |
} |
|
163 |
||
164 |
// --------------------------------------------------------------------------- |
|
165 |
// Chages status of message entry |
|
166 |
// --------------------------------------------------------------------------- |
|
167 |
// |
|
168 |
EXPORT_C void CMessagingService::ChangeStatusL( const TMsvId aMessageId, |
|
169 |
const TMessageStatusFlag aStatusFlag, |
|
170 |
const TBool aFlagValue, |
|
171 |
CMsgCallbackBase* /*aCallback*/ ) |
|
172 |
{ |
|
173 |
CMessageChangeStatus* obj = CMessageChangeStatus::NewL( *iMsgServerSession ); |
|
174 |
||
175 |
CleanupStack::PushL( obj ); |
|
176 |
||
177 |
obj->ChangeStatusL( aMessageId, aStatusFlag, aFlagValue ); |
|
178 |
||
179 |
CleanupStack::PopAndDestroy( obj ); |
|
180 |
} |
|
181 |
||
182 |
// --------------------------------------------------------------------------- |
|
183 |
// Gives notification for new messages |
|
184 |
// --------------------------------------------------------------------------- |
|
185 |
// |
|
186 |
EXPORT_C TInt CMessagingService::RequestNotification( const TNotificationType /*aNotification*/, |
|
187 |
CMsgCallbackBase* aCallback ) |
|
188 |
{ |
|
189 |
// Only one object can get the new message notification |
|
190 |
if( ( (CMessageObserver*)iSessionObserver )->IsActive() ) |
|
191 |
return KErrAlreadyExists; |
|
192 |
||
193 |
CMsgCallbackBase* oldCallback = iSessionObserver->SetCallback( aCallback ); |
|
194 |
||
195 |
delete oldCallback; |
|
196 |
||
197 |
return KErrNone; |
|
198 |
} |
|
199 |
||
200 |
// --------------------------------------------------------------------------- |
|
201 |
// Cancels notification |
|
202 |
// --------------------------------------------------------------------------- |
|
203 |
// |
|
204 |
EXPORT_C TInt CMessagingService::CancelNotification( const TNotificationType /*aNotification*/, |
|
205 |
CMsgCallbackBase* /*aCallback*/ ) |
|
206 |
{ |
|
207 |
CMsgCallbackBase* oldCallback = iSessionObserver->SetCallback( NULL ); |
|
208 |
||
209 |
delete oldCallback; |
|
210 |
||
211 |
return KErrNone; |
|
212 |
} |
|
213 |
||
214 |
// --------------------------------------------------------------------------- |
|
215 |
// Gives a sorted list of message Ids |
|
216 |
// --------------------------------------------------------------------------- |
|
217 |
// |
|
218 |
EXPORT_C void CMessagingService::GetIdListL( CFilterParamInfo* aFilterParams, |
|
219 |
TMsvId /*aFolderId*/, |
|
10
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
220 |
CMsgCallbackBase* aCallback, |
5 | 221 |
CMsvEntrySelection*& aEntrySelection ) |
222 |
{ |
|
223 |
// Hard coding for Inbox/Draft |
|
224 |
// Folder Id can be passed as input parameter, to support access any folder |
|
225 |
TMsvId folderId = KFolderId; |
|
226 |
||
227 |
CMessagingAccessFolder* obj = CMessagingAccessFolder::NewL( *iMsgServerSession ); |
|
228 |
||
229 |
CleanupStack::PushL( obj ); |
|
230 |
||
10
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
231 |
obj->SetInputParamsL(aCallback,this); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
232 |
|
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
233 |
if ( aCallback ) |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
234 |
{ |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
235 |
AddAsyncObjL( aCallback->iTransactionId,obj); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
236 |
} |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
237 |
|
5 | 238 |
obj->GetIdListL( folderId, aFilterParams, aEntrySelection ); |
239 |
||
10
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
240 |
CleanupStack::Pop( obj ); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
241 |
|
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
242 |
if ( !aCallback ) |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
243 |
delete obj; |
5 | 244 |
} |
245 |
||
246 |
EXPORT_C void CMessagingService::GetNextHeaderL( CFilterParamInfo* aFilterParams, |
|
247 |
CMsvEntrySelection* aEntrySelection, |
|
248 |
TInt& aIndex, |
|
249 |
CMsgCallbackBase* /*aCallback*/, |
|
250 |
CMessageHeader*& aHeader ) |
|
251 |
{ |
|
252 |
CMessagingAccessFolder* obj = CMessagingAccessFolder::NewL( *iMsgServerSession ); |
|
253 |
||
254 |
CleanupStack::PushL( obj ); |
|
255 |
||
256 |
obj->GetNextHeaderL( aFilterParams, aEntrySelection, aIndex, aHeader ); |
|
257 |
||
258 |
CleanupStack::PopAndDestroy( obj ); |
|
259 |
} |
|
260 |
||
261 |
// --------------------------------------------------------------------------- |
|
262 |
// Gives details of the message |
|
263 |
// --------------------------------------------------------------------------- |
|
264 |
// |
|
265 |
EXPORT_C void CMessagingService::GetMessageDetailL( const TMsvId aMessageId, |
|
266 |
CMsgCallbackBase* /*aCallback*/, |
|
267 |
CMessageDetailInfo*& aResult ) |
|
268 |
{ |
|
269 |
CMessageDetail* obj = CMessageDetail::NewL( *iMsgServerSession ); |
|
270 |
||
271 |
CleanupStack::PushL( obj ); |
|
272 |
||
273 |
obj->GetMessageDetailL( aMessageId, aResult ); |
|
274 |
||
275 |
CleanupStack::PopAndDestroy( obj ); |
|
276 |
} |
|
277 |
||
278 |
// --------------------------------------------------------------------------- |
|
279 |
// Adds asynchronous request object |
|
280 |
// --------------------------------------------------------------------------- |
|
281 |
// |
|
282 |
void CMessagingService::AddAsyncObjL( const TInt32 aTransactionId, CActive* aAsyncObj ) |
|
283 |
{ |
|
284 |
TAsyncRequestInfo asyncRequestInfo; |
|
285 |
asyncRequestInfo.iTransactionId = aTransactionId; |
|
286 |
asyncRequestInfo.iAsyncObj = aAsyncObj; |
|
287 |
User::LeaveIfError( iAsyncObjArray.Append( asyncRequestInfo ) ); |
|
288 |
} |
|
289 |
||
290 |
// --------------------------------------------------------------------------- |
|
291 |
// Deletes all the asynchronous request objects |
|
292 |
// --------------------------------------------------------------------------- |
|
293 |
// |
|
294 |
void CMessagingService::DeleteAsyncObjects() |
|
295 |
{ |
|
296 |
TInt pos = iAsyncObjArray.Count() - 1; |
|
297 |
TAsyncRequestInfo obj; |
|
298 |
for ( ; pos >= 0; pos-- ) |
|
299 |
{ |
|
300 |
obj = iAsyncObjArray[pos]; |
|
301 |
(obj.iAsyncObj)->Cancel(); |
|
302 |
delete obj.iAsyncObj; |
|
303 |
} |
|
304 |
} |
|
305 |
||
306 |
||
307 |
// --------------------------------------------------------------------------- |
|
308 |
// Cancels asynchronous request |
|
309 |
// --------------------------------------------------------------------------- |
|
310 |
// |
|
311 |
EXPORT_C TInt CMessagingService::Cancel( const TInt32 aTransactionId ) |
|
312 |
{ |
|
313 |
TInt pos = iAsyncObjArray.Count() - 1; |
|
314 |
TAsyncRequestInfo obj; |
|
315 |
for ( ; pos >= 0; pos-- ) |
|
316 |
{ |
|
317 |
obj = iAsyncObjArray[pos]; |
|
318 |
if( obj.iTransactionId == aTransactionId ) |
|
319 |
{ |
|
320 |
obj.iAsyncObj->Cancel(); |
|
321 |
delete obj.iAsyncObj; |
|
322 |
return KErrNone; |
|
323 |
} |
|
324 |
} |
|
325 |
return KErrNotFound; |
|
326 |
} |
|
327 |
||
328 |
||
329 |
// --------------------------------------------------------------------------- |
|
330 |
// Notifies Messaging service about the completeion of the request |
|
331 |
// --------------------------------------------------------------------------- |
|
332 |
// |
|
333 |
void CMessagingService::RequestComplete( const TInt32 aTransactionId ) |
|
334 |
{ |
|
335 |
TInt pos = iAsyncObjArray.Count() - 1; |
|
336 |
TAsyncRequestInfo obj; |
|
337 |
for ( ; pos >= 0; pos-- ) |
|
338 |
{ |
|
339 |
obj = iAsyncObjArray[pos]; |
|
340 |
if( obj.iTransactionId == aTransactionId ) |
|
341 |
{ |
|
342 |
iAsyncObjArray.Remove(pos); |
|
343 |
iAsyncObjArray.Compress(); |
|
344 |
return; |
|
345 |
} |
|
346 |
} |
|
347 |
} |
|
348 |