31
|
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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <textresolver.h> // from CommonEngine
|
|
19 |
#include <mtclreg.h>
|
|
20 |
#include <mmsnotificationclient.h>
|
|
21 |
#include <mmssettings.h>
|
|
22 |
#include <xqconversions.h> // from xqutils
|
|
23 |
#include <mmsconst.h>
|
|
24 |
#include <QDateTime>
|
|
25 |
|
|
26 |
#include "conversationmsgstorehandler.h"
|
|
27 |
#include "draftsmodel.h"
|
|
28 |
#include "MuiuOperationWait.h"
|
|
29 |
#include "MsgBioUids.h"
|
|
30 |
#include "UniEditorGenUtils.h"
|
|
31 |
|
|
32 |
// SYSTEM INCLUDES
|
|
33 |
#include <StringLoader.h>
|
|
34 |
#include <ccsdefs.h>
|
|
35 |
#include <msvids.h>
|
|
36 |
#include <mmserrors.h>
|
|
37 |
#include <msvuids.h>
|
|
38 |
#include <smut.h>
|
|
39 |
#include <SendUiConsts.h>
|
|
40 |
#include <featmgr.h>
|
|
41 |
#include <gsmerror.h>
|
|
42 |
|
|
43 |
// CONSTANTS
|
|
44 |
const TUid KSmsMtmUid ={KSenduiMtmSmsUidValue};
|
|
45 |
const TUid KMmsMtmUid ={KSenduiMtmMmsUidValue};
|
|
46 |
_LIT(KUnixEpoch, "19700000:000000.000000");
|
|
47 |
#define BYTES_TO_KBYTES_FACTOR 1024
|
|
48 |
|
|
49 |
// TODO: read global setting of formats on the phone
|
|
50 |
const QString DATE_FORMAT("dd/MM");
|
|
51 |
const QString TIME_FORMAT("hh:mm");
|
|
52 |
|
|
53 |
// ================= MEMBER FUNCTIONS =======================
|
|
54 |
|
|
55 |
// ---------------------------------------------------------
|
|
56 |
// Default constructor.
|
|
57 |
// ---------------------------------------------------------
|
|
58 |
//
|
|
59 |
ConversationMsgStoreHandler::ConversationMsgStoreHandler():
|
|
60 |
iMsvSession(NULL),iDraftEntry(NULL),iDraftMessages(NULL),mDraftsModel(NULL),
|
|
61 |
iMtmReg(NULL),iMmsClient(NULL),iNotificationClient(NULL)
|
|
62 |
{
|
|
63 |
TRAP_IGNORE(InitL());
|
|
64 |
}
|
|
65 |
|
|
66 |
// ---------------------------------------------------------
|
|
67 |
// Destructor.
|
|
68 |
// ---------------------------------------------------------
|
|
69 |
//
|
|
70 |
ConversationMsgStoreHandler::~ConversationMsgStoreHandler()
|
|
71 |
{
|
|
72 |
if ( iDraftEntry )
|
|
73 |
{
|
|
74 |
delete iDraftEntry;
|
|
75 |
iDraftEntry = NULL;
|
|
76 |
}
|
|
77 |
|
|
78 |
if ( iDraftMessages )
|
|
79 |
{
|
|
80 |
iDraftMessages->Reset();
|
|
81 |
delete iDraftMessages;
|
|
82 |
iDraftMessages = NULL;
|
|
83 |
}
|
|
84 |
|
|
85 |
if (iMmsClient)
|
|
86 |
{
|
|
87 |
delete iMmsClient;
|
|
88 |
iMmsClient = NULL;
|
|
89 |
}
|
|
90 |
if (iNotificationClient)
|
|
91 |
{
|
|
92 |
delete iNotificationClient;
|
|
93 |
iNotificationClient = NULL;
|
|
94 |
}
|
|
95 |
if (iMtmReg)
|
|
96 |
{
|
|
97 |
delete iMtmReg;
|
|
98 |
iMtmReg = NULL;
|
|
99 |
}
|
|
100 |
if (iMsvSession)
|
|
101 |
{
|
|
102 |
delete iMsvSession;
|
|
103 |
iMsvSession = NULL;
|
|
104 |
}
|
|
105 |
}
|
|
106 |
|
|
107 |
// ---------------------------------------------------------
|
|
108 |
//
|
|
109 |
// ---------------------------------------------------------
|
|
110 |
//
|
|
111 |
void ConversationMsgStoreHandler::InitL( )
|
|
112 |
{
|
|
113 |
TInt err = KErrNone;
|
|
114 |
TRAP(err,iMsvSession = CMsvSession::OpenSyncL(*this));
|
|
115 |
if(err != KErrNone)
|
|
116 |
{
|
|
117 |
iMsvSession = NULL;
|
|
118 |
return;
|
|
119 |
}
|
|
120 |
|
|
121 |
TRAP(err,iMtmReg = CClientMtmRegistry::NewL(*iMsvSession));
|
|
122 |
if(err != KErrNone)
|
|
123 |
{
|
|
124 |
iMtmReg = NULL;
|
|
125 |
return;
|
|
126 |
}
|
|
127 |
|
|
128 |
// Get if offline is supported
|
|
129 |
FeatureManager::InitializeLibL();
|
|
130 |
if (FeatureManager::FeatureSupported(KFeatureIdOfflineMode))
|
|
131 |
{
|
|
132 |
iOfflineSupported = ETrue;
|
|
133 |
}
|
|
134 |
else
|
|
135 |
{
|
|
136 |
iOfflineSupported = EFalse;
|
|
137 |
}
|
|
138 |
FeatureManager::UnInitializeLib();
|
|
139 |
|
|
140 |
}
|
|
141 |
|
|
142 |
// ---------------------------------------------------------
|
|
143 |
// ConversationMsgStoreHandler::HandleSessionEventL()
|
|
144 |
// ---------------------------------------------------------
|
|
145 |
//
|
|
146 |
void ConversationMsgStoreHandler::HandleSessionEventL(TMsvSessionEvent aEvent,
|
|
147 |
TAny* aArg1, TAny* aArg2, TAny* aArg3)
|
|
148 |
{
|
|
149 |
//args
|
|
150 |
if(aArg1 == NULL || aArg2 == NULL)
|
|
151 |
{
|
|
152 |
return;
|
|
153 |
}
|
|
154 |
|
|
155 |
//start, processing the event
|
|
156 |
CMsvEntrySelection* selection=NULL;
|
|
157 |
TMsvId target = 0;
|
|
158 |
TMsvId source = 0;
|
|
159 |
selection= (CMsvEntrySelection*)aArg1;
|
|
160 |
target = *(TMsvId*)aArg2; // target (current) parent
|
|
161 |
if(aArg3 != NULL)
|
|
162 |
{
|
|
163 |
source = *(TMsvId*)aArg3; // source parent
|
|
164 |
}
|
|
165 |
//process for draft messages only
|
|
166 |
if ( target == KMsvDraftEntryIdValue)
|
|
167 |
{
|
|
168 |
switch( aEvent )
|
|
169 |
{
|
|
170 |
//case EMsvEntriesCreated:
|
|
171 |
case EMsvEntriesChanged:
|
|
172 |
case EMsvEntriesMoved:
|
|
173 |
{
|
|
174 |
TMsvEntry entry;
|
|
175 |
TMsvId service;
|
|
176 |
TInt error= KErrNone;
|
|
177 |
|
|
178 |
for( TInt i=0 ; i < selection->Count() ; ++i )
|
|
179 |
{
|
|
180 |
error = iMsvSession->GetEntry(selection->At(i),service,entry);
|
|
181 |
if (KErrNone == error)
|
|
182 |
{
|
|
183 |
// process only visible entries
|
|
184 |
if (entry.Visible() && IsMtmSupported(entry.iMtm.iUid))
|
|
185 |
{
|
|
186 |
if(mDraftsModel && mDraftsModel->isReady())
|
|
187 |
{
|
|
188 |
mDraftsModel->addRow(entry);
|
|
189 |
}
|
|
190 |
}
|
|
191 |
}
|
|
192 |
}
|
|
193 |
}
|
|
194 |
break;
|
|
195 |
|
|
196 |
case EMsvEntriesDeleted:
|
|
197 |
{
|
|
198 |
for( TInt i=0 ; i < selection->Count() ; ++i )
|
|
199 |
{
|
|
200 |
TMsvId id = selection->At( i );
|
|
201 |
if(mDraftsModel && mDraftsModel->isReady())
|
|
202 |
{
|
|
203 |
mDraftsModel->deleteRow(id);
|
|
204 |
}
|
|
205 |
}
|
|
206 |
}
|
|
207 |
break;
|
|
208 |
}//end switch
|
|
209 |
}
|
|
210 |
else if(KMsvDraftEntryIdValue == source)
|
|
211 |
{
|
|
212 |
//if message is moved from drafts to other folder
|
|
213 |
// it needs to be removed.
|
|
214 |
if(aEvent == EMsvEntriesMoved)
|
|
215 |
{
|
|
216 |
for( TInt i=0 ; i < selection->Count() ; ++i )
|
|
217 |
{
|
|
218 |
TMsvId id = selection->At( i );
|
|
219 |
if(mDraftsModel && mDraftsModel->isReady())
|
|
220 |
{
|
|
221 |
mDraftsModel->deleteRow(id);
|
|
222 |
}
|
|
223 |
}
|
|
224 |
}
|
|
225 |
}
|
|
226 |
}
|
|
227 |
|
|
228 |
// ---------------------------------------------------------
|
|
229 |
// ConversationMsgStoreHandler::MsgStatus
|
|
230 |
// ---------------------------------------------------------
|
|
231 |
//
|
|
232 |
TCsMmsNotificationMsgState ConversationMsgStoreHandler::
|
|
233 |
MmsNotificationStatus( TInt aMsvId )
|
|
234 |
{
|
|
235 |
TMsvId dummy = 0x0;
|
|
236 |
|
|
237 |
TMsvEntry entry;
|
|
238 |
iMsvSession->GetEntry(aMsvId, dummy, entry);
|
|
239 |
|
|
240 |
TCsMmsNotificationMsgState status = EMsgStatusNull;
|
|
241 |
|
|
242 |
TTime currentTime;
|
|
243 |
currentTime.HomeTime( );
|
|
244 |
TTime expiryTime = iNotificationClient->ExpiryDate( );
|
|
245 |
TLocale locale;
|
|
246 |
expiryTime += locale.UniversalTimeOffset();
|
|
247 |
if (locale.QueryHomeHasDaylightSavingOn())
|
|
248 |
{
|
|
249 |
TTimeIntervalHours daylightSaving(1);
|
|
250 |
expiryTime += daylightSaving;
|
|
251 |
}
|
|
252 |
|
|
253 |
// operationMask includes operation type. It is not bitmap but ordinal number.
|
|
254 |
// It does not include operation status and result
|
|
255 |
TInt operationMask = (entry.iMtmData2 & KMmsOperationIdentifier) ;
|
|
256 |
|
|
257 |
// Note! Ongoing operation resets every bit of operation type, operation status
|
|
258 |
// and result. E.g. If message has been forwarded and then fetching starts,
|
|
259 |
// information about forwarding is lost
|
|
260 |
|
|
261 |
if( ( entry.iMtmData1 & KMmsMessageTypeMask ) == KMmsMessageMNotificationInd )
|
|
262 |
{
|
|
263 |
if( operationMask == KMmsOperationFetch
|
|
264 |
&& OperationOngoing( entry ) )
|
|
265 |
{
|
|
266 |
// It's in retrieving state
|
|
267 |
status = EMsgStatusRetrieving;
|
|
268 |
}
|
|
269 |
else if( operationMask == KMmsOperationForward
|
|
270 |
&& OperationOngoing( entry ) )
|
|
271 |
{
|
|
272 |
// It's in forwarding state
|
|
273 |
status = EMsgStatusForwarding;
|
|
274 |
}
|
|
275 |
else if( operationMask == KMmsOperationForward
|
|
276 |
&& OperationFinished( entry )
|
|
277 |
&& !( entry.iMtmData2 & KMmsOperationResult ) )
|
|
278 |
{
|
|
279 |
// It's been forwarded succesfully
|
|
280 |
status = EMsgStatusForwarded;
|
|
281 |
}
|
|
282 |
else if( operationMask == KMmsOperationFetch
|
|
283 |
&& OperationFinished( entry )
|
|
284 |
&& ( entry.iMtmData2 & KMmsOperationResult
|
|
285 |
|| entry.iError ) )
|
|
286 |
{
|
|
287 |
// Fetch has been failed
|
|
288 |
status = EMsgStatusFailed;
|
|
289 |
}
|
|
290 |
else if( operationMask == KMmsOperationDelete
|
|
291 |
&& OperationFinished( entry )
|
|
292 |
&& !( entry.iMtmData2 & KMmsOperationResult ) )
|
|
293 |
{
|
|
294 |
// It's been deleted succesfully
|
|
295 |
status = EMsgStatusDeleted;
|
|
296 |
}
|
|
297 |
else if( currentTime > expiryTime )
|
|
298 |
{
|
|
299 |
status = EMsgStatusExpired;
|
|
300 |
}
|
|
301 |
else
|
|
302 |
{ // Normal waiting state
|
|
303 |
status = EMsgStatusReadyForFetching;
|
|
304 |
}
|
|
305 |
}
|
|
306 |
|
|
307 |
return status;
|
|
308 |
}
|
|
309 |
|
|
310 |
// ---------------------------------------------------------
|
|
311 |
// ConversationMsgStoreHandler::OperationOngoing
|
|
312 |
// ---------------------------------------------------------
|
|
313 |
//
|
|
314 |
TBool ConversationMsgStoreHandler::OperationOngoing( const TMsvEntry& aEntry ) const
|
|
315 |
{
|
|
316 |
return ( aEntry.iMtmData2 & KMmsOperationOngoing
|
|
317 |
&& !( aEntry.iMtmData2 & KMmsOperationFinished ) );
|
|
318 |
}
|
|
319 |
|
|
320 |
// ---------------------------------------------------------
|
|
321 |
// ConversationMsgStoreHandler::OperationFinished
|
|
322 |
// ---------------------------------------------------------
|
|
323 |
//
|
|
324 |
TBool ConversationMsgStoreHandler::OperationFinished(
|
|
325 |
const TMsvEntry& aEntry ) const
|
|
326 |
{
|
|
327 |
return ( aEntry.iMtmData2 & KMmsOperationFinished
|
|
328 |
&& !( aEntry.iMtmData2 & KMmsOperationOngoing ) );
|
|
329 |
}
|
|
330 |
|
|
331 |
// ---------------------------------------------------------
|
|
332 |
// ConversationMsgStoreHandler::MarkMessagesReadL
|
|
333 |
// ---------------------------------------------------------
|
|
334 |
//
|
|
335 |
void ConversationMsgStoreHandler::MarkMessagesReadL(RArray<TInt>& aIdArray)
|
|
336 |
{
|
|
337 |
for ( int index = 0; index < aIdArray.Count(); index++ )
|
|
338 |
{
|
|
339 |
TMsvId id = aIdArray[index];
|
|
340 |
CMsvEntry* cEntry = NULL;
|
|
341 |
TRAPD(err, cEntry = iMsvSession->GetEntryL(id));
|
|
342 |
if ( err == KErrNotFound )
|
|
343 |
continue; // Entry is already deleted.
|
|
344 |
TMsvEntry entry = cEntry->Entry();
|
|
345 |
if ( entry.Unread() )
|
|
346 |
{
|
|
347 |
// Mark the entry as read
|
|
348 |
entry.SetUnread( EFalse );
|
|
349 |
cEntry->ChangeL( entry );
|
|
350 |
}
|
|
351 |
delete cEntry;
|
|
352 |
}
|
|
353 |
}
|
|
354 |
|
|
355 |
// ---------------------------------------------------------
|
|
356 |
// ConversationMsgStoreHandler::DeleteMessages
|
|
357 |
// ---------------------------------------------------------
|
|
358 |
//
|
|
359 |
void ConversationMsgStoreHandler::DeleteMessages(RArray<TInt>& aIdArray)
|
|
360 |
{
|
|
361 |
for(int index=0;index < aIdArray.Count() ;++index)
|
|
362 |
{
|
|
363 |
TMsvId id = aIdArray[index];
|
|
364 |
iMsvSession->RemoveEntry(id);
|
|
365 |
}
|
|
366 |
}
|
|
367 |
|
|
368 |
// ---------------------------------------------------------
|
|
369 |
// ConversationMsgStoreHandler::DeleteAllDraftMessages
|
|
370 |
// ---------------------------------------------------------
|
|
371 |
//
|
|
372 |
void ConversationMsgStoreHandler::DeleteAllDraftMessagesL()
|
|
373 |
{
|
|
374 |
// Cancel the processing of draft messages.
|
|
375 |
iIdle->Cancel();
|
|
376 |
|
|
377 |
CMsvEntry *draftsEntry = iMsvSession->GetEntryL(KMsvDraftEntryIdValue);
|
|
378 |
CleanupStack::PushL(draftsEntry);
|
|
379 |
CMsvEntrySelection *draftsSelection = draftsEntry->ChildrenL();
|
|
380 |
CleanupStack::PushL(draftsSelection);
|
|
381 |
if ( draftsSelection->Count() > 0 )
|
|
382 |
{
|
|
383 |
CMuiuOperationWait* wait = CMuiuOperationWait::NewLC();
|
|
384 |
CMsvOperation *operation = draftsEntry->DeleteL(*draftsSelection, wait->iStatus);
|
|
385 |
wait->Start();
|
|
386 |
CleanupStack::PopAndDestroy(wait);
|
|
387 |
delete operation;
|
|
388 |
}
|
|
389 |
CleanupStack::PopAndDestroy(2, draftsEntry);
|
|
390 |
}
|
|
391 |
|
|
392 |
// ---------------------------------------------------------
|
|
393 |
// ConversationMsgStoreHandler::DeleteMessagesL
|
|
394 |
// ---------------------------------------------------------
|
|
395 |
//
|
|
396 |
CMsvSession& ConversationMsgStoreHandler::GetMsvSession()
|
|
397 |
{
|
|
398 |
return *iMsvSession;
|
|
399 |
}
|
|
400 |
|
|
401 |
// ---------------------------------------------------------
|
|
402 |
// ConversationMsgStoreHandler::FetchDraftsMessages
|
|
403 |
// ---------------------------------------------------------
|
|
404 |
//
|
|
405 |
void ConversationMsgStoreHandler::FetchDraftMessages(DraftsModel* draftsModel)
|
|
406 |
{
|
|
407 |
mDraftsModel = draftsModel;
|
|
408 |
iState = EReadDrafts;
|
|
409 |
TCallBack callback = TCallBack(ProcessDraftMessages, (TAny*) this);
|
|
410 |
TRAPD(err, iIdle = CIdle::NewL(CActive::EPriorityStandard));
|
|
411 |
if(err == KErrNone)
|
|
412 |
{
|
|
413 |
iIdle->Start(callback);
|
|
414 |
}
|
|
415 |
}
|
|
416 |
|
|
417 |
// -----------------------------------------------------------------------------
|
|
418 |
// ConversationMsgStoreHandler::ProcessDraftMessages
|
|
419 |
// CIdle callback
|
|
420 |
// -----------------------------------------------------------------------------
|
|
421 |
//
|
|
422 |
TInt ConversationMsgStoreHandler::ProcessDraftMessages(TAny* aArg)
|
|
423 |
{
|
|
424 |
ConversationMsgStoreHandler* handler = (ConversationMsgStoreHandler*) aArg;
|
|
425 |
TInt ok = 0;
|
|
426 |
TRAPD(err, ok = handler->ProcessDraftMessagesL());
|
|
427 |
return ((err == KErrNone) && ok);
|
|
428 |
}
|
|
429 |
|
|
430 |
// ---------------------------------------------------------
|
|
431 |
// ConversationMsgStoreHandler::ProcessDraftMessagesL
|
|
432 |
// ---------------------------------------------------------
|
|
433 |
//
|
|
434 |
TInt ConversationMsgStoreHandler::ProcessDraftMessagesL()
|
|
435 |
{
|
|
436 |
switch(iState)
|
|
437 |
{
|
|
438 |
case EReadDrafts:
|
|
439 |
{
|
|
440 |
iDraftEntry = iMsvSession->GetEntryL(KMsvDraftEntryIdValue);
|
|
441 |
|
|
442 |
iDraftMessages = iDraftEntry->ChildrenL();
|
|
443 |
iDraftMessageCount = iDraftEntry->Count();
|
|
444 |
|
|
445 |
if ( iDraftMessageCount )
|
|
446 |
{
|
|
447 |
iState = EProcessDrafts;
|
|
448 |
}
|
|
449 |
else
|
|
450 |
{
|
|
451 |
iState = EComplete; // no draft messages
|
|
452 |
mDraftsModel->setReady(); //ready to handle dynamic events
|
|
453 |
CleanupL();
|
|
454 |
return 0; //DONE
|
|
455 |
}
|
|
456 |
return 1;
|
|
457 |
}
|
|
458 |
case EProcessDrafts:
|
|
459 |
{
|
|
460 |
if ( iDraftMessageCount )
|
|
461 |
{
|
|
462 |
iDraftMessageCount--;
|
|
463 |
TMsvEntry entry = iDraftEntry->ChildDataL(
|
|
464 |
iDraftMessages->At(iDraftMessageCount));
|
|
465 |
|
|
466 |
// process only visible entries
|
|
467 |
if (entry.Visible() && IsMtmSupported(entry.iMtm.iUid))
|
|
468 |
{
|
|
469 |
//add message to model
|
|
470 |
mDraftsModel->addRow(entry);
|
|
471 |
}
|
|
472 |
//continue to process other draft messages
|
|
473 |
iState = EProcessDrafts;
|
|
474 |
}
|
|
475 |
else
|
|
476 |
{
|
|
477 |
iState = EComplete;
|
|
478 |
mDraftsModel->setReady(); //ready to handle dynamic events
|
|
479 |
CleanupL();
|
|
480 |
return 0; // DONE
|
|
481 |
}
|
|
482 |
return 1;
|
|
483 |
}
|
|
484 |
}
|
|
485 |
|
|
486 |
return 0;
|
|
487 |
}
|
|
488 |
|
|
489 |
// -----------------------------------------------------------------------------
|
|
490 |
// ConversationMsgStoreHandler::CleanupL()
|
|
491 |
// Helper function for state machine cleanup
|
|
492 |
// -----------------------------------------------------------------------------
|
|
493 |
//
|
|
494 |
void ConversationMsgStoreHandler::CleanupL()
|
|
495 |
{
|
|
496 |
if ( iDraftEntry )
|
|
497 |
{
|
|
498 |
delete iDraftEntry;
|
|
499 |
iDraftEntry = NULL;
|
|
500 |
}
|
|
501 |
|
|
502 |
if ( iDraftMessages )
|
|
503 |
{
|
|
504 |
iDraftMessages->Reset();
|
|
505 |
delete iDraftMessages;
|
|
506 |
iDraftMessages = NULL;
|
|
507 |
}
|
|
508 |
|
|
509 |
iDraftMessageCount = 0;
|
|
510 |
}
|
|
511 |
|
|
512 |
// -----------------------------------------------------------------------------
|
|
513 |
// ConversationMsgStoreHandler::IsMtmSupported()
|
|
514 |
//
|
|
515 |
// -----------------------------------------------------------------------------
|
|
516 |
//
|
|
517 |
TBool ConversationMsgStoreHandler::IsMtmSupported(long uid)
|
|
518 |
{
|
|
519 |
if ( KSenduiMtmSmsUidValue == uid || KSenduiMtmMmsUidValue == uid )
|
|
520 |
{
|
|
521 |
return ETrue;
|
|
522 |
}
|
|
523 |
return EFalse;
|
|
524 |
}
|
|
525 |
|
|
526 |
//-----------------------------------------------------------------------------
|
|
527 |
// ConversationMsgStoreHandler::ResendMessage(TMsvId aId)
|
|
528 |
//
|
|
529 |
// -----------------------------------------------------------------------------
|
|
530 |
//
|
|
531 |
|
|
532 |
bool ConversationMsgStoreHandler::ResendMessageL(TMsvId aId)
|
|
533 |
{
|
|
534 |
bool retval = true;
|
|
535 |
TMsvId serviceId;
|
|
536 |
TMsvEntry msgEntry;
|
|
537 |
|
|
538 |
if(iMsvSession == NULL)
|
|
539 |
{
|
|
540 |
return false;
|
|
541 |
}
|
|
542 |
TInt err = iMsvSession->GetEntry(aId, serviceId, msgEntry);
|
|
543 |
|
|
544 |
if (KErrNone == err)
|
|
545 |
{
|
|
546 |
TUid mtmUid = msgEntry.iMtm;
|
|
547 |
|
|
548 |
CMsvEntry* entry = iMsvSession->GetEntryL(KMsvGlobalOutBoxIndexEntryId);
|
|
549 |
CleanupStack::PushL(entry);
|
|
550 |
|
|
551 |
CMuiuOperationWait* wait = CMuiuOperationWait::NewLC();
|
|
552 |
|
|
553 |
if (mtmUid == KSmsMtmUid)
|
|
554 |
{
|
|
555 |
UniEditorGenUtils* genUtils = new UniEditorGenUtils();
|
|
556 |
CleanupStack::PushL(genUtils);
|
|
557 |
|
|
558 |
// if phone is in offline mode set sending state to suspended
|
|
559 |
// so that mtm does not try to send it.
|
|
560 |
if (iOfflineSupported && genUtils->IsPhoneOfflineL())
|
|
561 |
{
|
|
562 |
msgEntry.SetSendingState(KMsvSendStateSuspended);
|
|
563 |
msgEntry.iError = KErrGsmOfflineOpNotAllowed;
|
|
564 |
}
|
|
565 |
else
|
|
566 |
{
|
|
567 |
msgEntry.SetSendingState(KMsvSendStateWaiting);
|
|
568 |
}
|
|
569 |
CleanupStack::PopAndDestroy(genUtils);
|
|
570 |
|
|
571 |
// Update message entry with sending state.
|
|
572 |
entry->SetEntryL(msgEntry.Id());
|
|
573 |
entry->ChangeL(msgEntry);
|
|
574 |
|
|
575 |
TMsvId firstId;
|
|
576 |
TSmsUtilities::ServiceIdL(*iMsvSession, firstId);
|
|
577 |
|
|
578 |
entry->SetEntryL(KMsvGlobalOutBoxIndexEntryId);
|
|
579 |
//send the message
|
|
580 |
entry->CopyL(aId, firstId, wait->iStatus);
|
|
581 |
wait->Start();
|
|
582 |
}
|
|
583 |
else if (mtmUid == KMmsMtmUid)
|
|
584 |
{
|
|
585 |
//send the message
|
|
586 |
entry->CopyL(aId, msgEntry.iServiceId, wait->iStatus);
|
|
587 |
wait->Start();
|
|
588 |
}
|
|
589 |
CleanupStack::PopAndDestroy(2, entry);
|
|
590 |
}
|
|
591 |
else
|
|
592 |
{
|
|
593 |
User::LeaveIfError(err);
|
|
594 |
}
|
|
595 |
return retval;
|
|
596 |
}
|
|
597 |
|
|
598 |
//-----------------------------------------------------------------------------
|
|
599 |
// ConversationMsgStoreHandler::DownloadOperationSupported
|
|
600 |
// -----------------------------------------------------------------------------
|
|
601 |
bool ConversationMsgStoreHandler::DownloadOperationSupported(
|
|
602 |
const TMsvId& aId)
|
|
603 |
{
|
|
604 |
TMsvId serviceId;
|
|
605 |
TMsvEntry msgEntry;
|
|
606 |
TInt err = iMsvSession->GetEntry(aId,serviceId,msgEntry);
|
|
607 |
|
|
608 |
TCsMmsNotificationMsgState msgstatus =
|
|
609 |
MmsNotificationStatus( aId );
|
|
610 |
|
|
611 |
if ( msgEntry.iType == KUidMsvMessageEntry )
|
|
612 |
{
|
|
613 |
|
|
614 |
if( msgEntry.iMtmData2 & KMmsNewOperationForbidden ) // New Forbidden
|
|
615 |
{
|
|
616 |
return false;
|
|
617 |
}
|
|
618 |
// If notification is succesfully routed to app
|
|
619 |
// aContext.iMtmData2 & KMmsMessageRoutedToApplication is ETrue and
|
|
620 |
// if notification is NOT succesfully routed to app
|
|
621 |
// aContext.iError is KMmsErrorUnregisteredApplication.
|
|
622 |
if( ( msgEntry.iError == KMmsErrorUnregisteredApplication ) // To unregistered application
|
|
623 |
|| ( msgEntry.iMtmData2 & KMmsMessageRoutedToApplication ) )
|
|
624 |
{
|
|
625 |
return false;
|
|
626 |
}
|
|
627 |
|
|
628 |
if( msgstatus == EMsgStatusDeleted )
|
|
629 |
{ // Msg already been deleted from server
|
|
630 |
return false;
|
|
631 |
}
|
|
632 |
|
|
633 |
if( msgstatus == EMsgStatusReadyForFetching
|
|
634 |
|| msgstatus == EMsgStatusFailed )
|
|
635 |
{ // Fetch is supported if the msg is waiting or something has been failed
|
|
636 |
return true;
|
|
637 |
}
|
|
638 |
|
|
639 |
if ( msgstatus == EMsgStatusForwarded
|
|
640 |
&& msgEntry.iMtmData2 & KMmsStoredInMMBox )
|
|
641 |
{ // Fetch is supported if it's forwarded and multiple forward is supported
|
|
642 |
return true;
|
|
643 |
}
|
|
644 |
|
|
645 |
if( msgstatus == EMsgStatusExpired )
|
|
646 |
{
|
|
647 |
return false;
|
|
648 |
}
|
|
649 |
}
|
|
650 |
return false;
|
|
651 |
}
|
|
652 |
|
|
653 |
//---------------------------------------------------------------
|
|
654 |
// ConversationMsgStoreHandler::setNotificationMessageIdL
|
|
655 |
// @see header
|
|
656 |
//---------------------------------------------------------------
|
|
657 |
void ConversationMsgStoreHandler::setNotificationMessageIdL(int messageId)
|
|
658 |
{
|
|
659 |
// get MMS Notification client mtm & set the content to current entry
|
|
660 |
if(iNotificationClient)
|
|
661 |
{
|
|
662 |
delete iNotificationClient;
|
|
663 |
iNotificationClient = NULL;
|
|
664 |
}
|
|
665 |
CClientMtmRegistry* mtmRegistry =
|
|
666 |
CClientMtmRegistry::NewL( *iMsvSession );
|
|
667 |
iNotificationClient = static_cast<CMmsNotificationClientMtm*>(
|
|
668 |
mtmRegistry->NewMtmL( KUidMsgMMSNotification ));
|
|
669 |
iNotificationClient->SwitchCurrentEntryL(messageId);
|
|
670 |
iNotificationClient->LoadMessageL();
|
|
671 |
}
|
|
672 |
|
|
673 |
//---------------------------------------------------------------
|
|
674 |
// ConversationMsgStoreHandler::NotificationMsgSizeL
|
|
675 |
// @see header
|
|
676 |
//---------------------------------------------------------------
|
|
677 |
QString ConversationMsgStoreHandler::NotificationMsgSizeL()
|
|
678 |
{
|
|
679 |
// Size of message.
|
|
680 |
TInt size = iNotificationClient->MessageTransferSize( );
|
|
681 |
|
|
682 |
// read max receive size limit from settings
|
|
683 |
CMmsSettings* settings = CMmsSettings::NewL();
|
|
684 |
CleanupStack::PushL( settings );
|
|
685 |
iNotificationClient->RestoreSettingsL();
|
|
686 |
settings->CopyL( iNotificationClient->MmsSettings() );
|
|
687 |
TInt maxSize = static_cast<TInt>(settings->MaximumReceiveSize() );
|
|
688 |
CleanupStack::PopAndDestroy( settings );
|
|
689 |
|
|
690 |
// apply max size limit rule
|
|
691 |
if( maxSize > 0 )
|
|
692 |
{
|
|
693 |
if( size > maxSize )
|
|
694 |
{
|
|
695 |
size = maxSize;
|
|
696 |
}
|
|
697 |
}
|
|
698 |
|
|
699 |
// Finally make the UI string
|
|
700 |
int fileSize = size / BYTES_TO_KBYTES_FACTOR;
|
|
701 |
if ( size % BYTES_TO_KBYTES_FACTOR )
|
|
702 |
{
|
|
703 |
fileSize++;
|
|
704 |
}
|
|
705 |
// TODO: use localized string constants here
|
|
706 |
QString sizeString = QString("%1").arg(fileSize);
|
|
707 |
sizeString.append(" Kb");
|
|
708 |
return sizeString;
|
|
709 |
}
|
|
710 |
|
|
711 |
//---------------------------------------------------------------
|
|
712 |
// ConversationMsgStoreHandler::NotificationClass
|
|
713 |
// @see header
|
|
714 |
//---------------------------------------------------------------
|
|
715 |
QString ConversationMsgStoreHandler::NotificationClass()
|
|
716 |
{
|
|
717 |
//TODO: use localized string
|
|
718 |
QString notificationClass;
|
|
719 |
TInt msgClass = iNotificationClient->MessageClass( );
|
|
720 |
switch( msgClass )
|
|
721 |
{
|
|
722 |
case EMmsClassPersonal:
|
|
723 |
{
|
|
724 |
notificationClass = "Personal";
|
|
725 |
break;
|
|
726 |
}
|
|
727 |
case EMmsClassAdvertisement:
|
|
728 |
{
|
|
729 |
notificationClass = "Advertisement";
|
|
730 |
break;
|
|
731 |
}
|
|
732 |
case EMmsClassInformational:
|
|
733 |
{
|
|
734 |
notificationClass = "Informative";
|
|
735 |
break;
|
|
736 |
}
|
|
737 |
default:
|
|
738 |
{ // In case no class is returned (0), don't add the field
|
|
739 |
break;
|
|
740 |
}
|
|
741 |
}
|
|
742 |
return notificationClass;
|
|
743 |
}
|
|
744 |
|
|
745 |
//---------------------------------------------------------------
|
|
746 |
// ConversationMsgStoreHandler::NotificationStatus
|
|
747 |
// @see header
|
|
748 |
//---------------------------------------------------------------
|
|
749 |
void ConversationMsgStoreHandler::NotificationStatus(
|
|
750 |
int& status,
|
|
751 |
QString& statusStr)
|
|
752 |
{
|
|
753 |
// TODO : use standard strings provided by Arul
|
|
754 |
// fetch mms notification status from store handler
|
|
755 |
// and map as per our UI requirements
|
|
756 |
TMsvEntry entry = iNotificationClient->Entry().Entry();
|
|
757 |
status = MmsNotificationStatus(entry.Id());
|
|
758 |
switch(status)
|
|
759 |
{
|
|
760 |
case ConvergedMessage::NotifFailed:
|
|
761 |
{
|
|
762 |
statusStr = "Message retrieval failed !";
|
|
763 |
break;
|
|
764 |
}
|
|
765 |
case ConvergedMessage::NotifExpired:
|
|
766 |
{
|
|
767 |
statusStr = "Message Expired !";
|
|
768 |
break;
|
|
769 |
}
|
|
770 |
case ConvergedMessage::NotifReadyForFetching:
|
|
771 |
{
|
|
772 |
statusStr = "Multimedia Message waiting...";
|
|
773 |
break;
|
|
774 |
}
|
|
775 |
case ConvergedMessage::NotifWaiting:
|
|
776 |
case ConvergedMessage::NotifRetrieving:
|
|
777 |
{
|
|
778 |
statusStr = "Retrieving message...";
|
|
779 |
break;
|
|
780 |
}
|
|
781 |
default:
|
|
782 |
{
|
|
783 |
// not handled, do nothing
|
|
784 |
break;
|
|
785 |
}
|
|
786 |
}
|
|
787 |
}
|
|
788 |
|
|
789 |
//---------------------------------------------------------------
|
|
790 |
// ConversationMsgStoreHandler::NotificationExpiryDate
|
|
791 |
// @see header
|
|
792 |
//---------------------------------------------------------------
|
|
793 |
void ConversationMsgStoreHandler::NotificationExpiryDate(
|
|
794 |
TTime& expiryTime,
|
|
795 |
QString& expiryTimeStr)
|
|
796 |
{
|
|
797 |
// get expiry time from entry
|
|
798 |
expiryTime = iNotificationClient->ExpiryDate( );
|
|
799 |
TLocale locale;
|
|
800 |
expiryTime += locale.UniversalTimeOffset();
|
|
801 |
if (locale.QueryHomeHasDaylightSavingOn())
|
|
802 |
{
|
|
803 |
TTimeIntervalHours daylightSaving(1);
|
|
804 |
expiryTime += daylightSaving;
|
|
805 |
}
|
|
806 |
|
|
807 |
// create formatted string for the expiry time
|
|
808 |
TTime unixEpoch(KUnixEpoch);
|
|
809 |
TTimeIntervalSeconds seconds;
|
|
810 |
expiryTime.SecondsFrom(unixEpoch, seconds);
|
|
811 |
QDateTime dateTime;
|
|
812 |
dateTime.setTime_t(seconds.Int());
|
|
813 |
if (dateTime.date() == QDateTime::currentDateTime().date()) {
|
|
814 |
expiryTimeStr = dateTime.toString(TIME_FORMAT);
|
|
815 |
}
|
|
816 |
else {
|
|
817 |
expiryTimeStr = dateTime.toString(DATE_FORMAT);
|
|
818 |
}
|
|
819 |
}
|
|
820 |
|
|
821 |
//-----------------------------------------------------------------------------
|
|
822 |
// ConversationMsgStoreHandler::DownloadMessageL
|
|
823 |
//
|
|
824 |
// -----------------------------------------------------------------------------
|
|
825 |
//
|
|
826 |
|
|
827 |
TInt ConversationMsgStoreHandler::DownloadMessageL(TMsvId aId)
|
|
828 |
{
|
|
829 |
TMsvId serviceId;
|
|
830 |
TMsvEntry msgEntry;
|
|
831 |
|
|
832 |
TInt err = iMsvSession->GetEntry(aId,serviceId,msgEntry);
|
|
833 |
|
|
834 |
if(err!= KErrNone || msgEntry.iMtm!= KUidMsgMMSNotification)
|
|
835 |
{
|
|
836 |
return KErrGeneral;
|
|
837 |
}
|
|
838 |
|
|
839 |
/*if(!iNotificationClient)
|
|
840 |
{
|
|
841 |
iNotificationClient = static_cast<CMmsNotificationClientMtm*>
|
|
842 |
(iMtmReg->NewMtmL(KUidMsgMMSNotification));
|
|
843 |
}
|
|
844 |
iNotificationClient->SwitchCurrentEntryL(aId); */
|
|
845 |
|
|
846 |
// set context to current entry
|
|
847 |
setNotificationMessageIdL(aId);
|
|
848 |
|
|
849 |
TTime currentTime;
|
|
850 |
currentTime.HomeTime( );
|
|
851 |
TTime expiryTime = iNotificationClient->ExpiryDate( );
|
|
852 |
TLocale locale;
|
|
853 |
expiryTime += locale.UniversalTimeOffset();
|
|
854 |
if (locale.QueryHomeHasDaylightSavingOn())
|
|
855 |
{
|
|
856 |
TTimeIntervalHours daylightSaving(1);
|
|
857 |
expiryTime += daylightSaving;
|
|
858 |
}
|
|
859 |
|
|
860 |
if( currentTime > expiryTime )
|
|
861 |
{ // Message is expired
|
|
862 |
return KErrGeneral;
|
|
863 |
}
|
|
864 |
|
|
865 |
//Check if the mms client mtm object is already created or not
|
|
866 |
if( iMmsClient )
|
|
867 |
{
|
|
868 |
// If mms client mtm object is already created restore the settings
|
|
869 |
iMmsClient->RestoreSettingsL();
|
|
870 |
}
|
|
871 |
else
|
|
872 |
{
|
|
873 |
iMmsClient = static_cast<CMmsClientMtm*> (iMtmReg->NewMtmL(KMmsMtmUid));
|
|
874 |
}
|
|
875 |
|
|
876 |
//TODO chk if only AP check is sufficient
|
|
877 |
TMsvId service = iMmsClient->DefaultServiceL();
|
|
878 |
TBool valid( iMmsClient->ValidateService( service ) == KErrNone );
|
|
879 |
if(!valid)
|
|
880 |
{
|
|
881 |
return KErrNotFound;
|
|
882 |
}
|
|
883 |
|
|
884 |
CMuiuOperationWait* wait =CMuiuOperationWait::NewLC();;
|
|
885 |
|
|
886 |
CMsvEntrySelection* sel = new ( ELeave ) CMsvEntrySelection;
|
|
887 |
CleanupStack::PushL( sel );
|
|
888 |
sel->AppendL( aId );
|
|
889 |
|
|
890 |
CMsvOperation* op =
|
|
891 |
iNotificationClient->FetchMessagesL( *sel, wait->iStatus );
|
|
892 |
|
|
893 |
if( !op )
|
|
894 |
{
|
|
895 |
CleanupStack::PopAndDestroy( sel ); // selection
|
|
896 |
CleanupStack::PopAndDestroy( wait ); // wait
|
|
897 |
return KErrGeneral;
|
|
898 |
}
|
|
899 |
|
|
900 |
CleanupStack::PushL( op );
|
|
901 |
wait->Start();
|
|
902 |
// Lets ignore the return value of wait
|
|
903 |
|
|
904 |
CleanupStack::PopAndDestroy( op ); // op
|
|
905 |
CleanupStack::PopAndDestroy( sel ); // selection
|
|
906 |
CleanupStack::PopAndDestroy( wait ); // wait
|
|
907 |
|
|
908 |
return KErrNone;
|
|
909 |
}
|
|
910 |
|
|
911 |
//----------------------------------------------------------------------------
|
|
912 |
// ConversationMsgStoreHandler::markAsReadAndGetType
|
|
913 |
// @see header
|
|
914 |
//----------------------------------------------------------------------------
|
|
915 |
void ConversationMsgStoreHandler::markAsReadAndGetType(int msgId,
|
|
916 |
int& msgType,
|
|
917 |
int& msgSubType)
|
|
918 |
{
|
|
919 |
msgType = ConvergedMessage::None;
|
|
920 |
msgSubType = ConvergedMessage::None;
|
|
921 |
|
|
922 |
CMsvEntry* cEntry = NULL;
|
|
923 |
TRAPD(err, cEntry = iMsvSession->GetEntryL(msgId));
|
|
924 |
if ( err == KErrNone)
|
|
925 |
{
|
|
926 |
TMsvEntry entry = cEntry->Entry();
|
|
927 |
if ( entry.Unread() )
|
|
928 |
{
|
|
929 |
// Mark the entry as read
|
|
930 |
entry.SetUnread( EFalse );
|
|
931 |
TRAP_IGNORE(cEntry->ChangeL( entry ));
|
|
932 |
}
|
|
933 |
// extract message type
|
|
934 |
extractMsgType(entry,msgType,msgSubType);
|
|
935 |
}
|
|
936 |
|
|
937 |
delete cEntry;
|
|
938 |
}
|
|
939 |
|
|
940 |
//----------------------------------------------------------------------------
|
|
941 |
// ConversationMsgStoreHandler::extractMsgType
|
|
942 |
// @see header
|
|
943 |
//----------------------------------------------------------------------------
|
|
944 |
void ConversationMsgStoreHandler::extractMsgType(const TMsvEntry& entry,
|
|
945 |
int& msgType,
|
|
946 |
int& msgSubType)
|
|
947 |
{
|
|
948 |
msgType = ConvergedMessage::None;
|
|
949 |
msgSubType = ConvergedMessage::None;
|
|
950 |
|
|
951 |
switch(entry.iMtm.iUid)
|
|
952 |
{
|
|
953 |
case KSenduiMtmSmsUidValue:
|
|
954 |
msgType = ConvergedMessage::Sms;
|
|
955 |
break;
|
|
956 |
case KSenduiMtmBtUidValue:
|
|
957 |
msgType = ConvergedMessage::BT;
|
|
958 |
break;
|
|
959 |
case KSenduiMtmMmsUidValue:
|
|
960 |
msgType = ConvergedMessage::Mms;
|
|
961 |
break;
|
|
962 |
case KSenduiMMSNotificationUidValue:
|
|
963 |
msgType = ConvergedMessage::MmsNotification;
|
|
964 |
break;
|
|
965 |
case KSenduiMtmBioUidValue:
|
|
966 |
{
|
|
967 |
msgType = ConvergedMessage::BioMsg;
|
|
968 |
|
|
969 |
// based on the biotype uid set message type
|
|
970 |
if(entry.iBioType == KMsgBioUidRingingTone.iUid)
|
|
971 |
{
|
|
972 |
msgSubType = ConvergedMessage::RingingTone;
|
|
973 |
}
|
|
974 |
else if(entry.iBioType == KMsgBioProvisioningMessage.iUid)
|
|
975 |
{
|
|
976 |
msgSubType = ConvergedMessage::Provisioning;
|
|
977 |
}
|
|
978 |
else if (entry.iBioType == KMsgBioUidVCard.iUid)
|
|
979 |
{
|
|
980 |
msgSubType = ConvergedMessage::VCard;
|
|
981 |
}
|
|
982 |
else if (entry.iBioType == KMsgBioUidVCalendar.iUid)
|
|
983 |
{
|
|
984 |
msgSubType = ConvergedMessage::VCal;
|
|
985 |
}
|
|
986 |
}
|
|
987 |
break;
|
|
988 |
default:
|
|
989 |
msgType = ConvergedMessage::None;
|
|
990 |
break;
|
|
991 |
}
|
|
992 |
}
|
|
993 |
// End of file
|