40
|
1 |
/*
|
64
|
2 |
* Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies).
|
40
|
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: Part of SyncML Data Synchronization Plug In Adapter
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
#include <txtrich.h>
|
|
22 |
#include <smsclnt.h>
|
|
23 |
#include <smutset.h>
|
|
24 |
#include <smuthdr.h>
|
|
25 |
#include <smscmds.h>
|
|
26 |
#include <sysutil.h>
|
|
27 |
#include <gsmuelem.h>
|
|
28 |
#include <cntdb.h>
|
|
29 |
#include <cntitem.h>
|
|
30 |
#include <cntfldst.h>
|
|
31 |
#include "smsadaptermsvapi.h"
|
|
32 |
#include "logger.h"
|
|
33 |
#include "vmessageparser.h"
|
|
34 |
#include "smsdataproviderdefs.h"
|
|
35 |
|
|
36 |
|
|
37 |
// CONSTANTS
|
|
38 |
|
64
|
39 |
// The following string is "èéùìòÇØøÅåÆæßÉ£$¥¡ÄÖÑܧ¿äöñüà", expressed as standard \xNN escape codes
|
|
40 |
_LIT16(KSmsNonUnicodeChars, "\xe8\xe9\xf9\xec\xf2\xc7\xd8\xf8\xc5\xe5\xc6\xe6\xdf\xc9\xa3$\xa5\xa1\xc4\xd6\xd1\xdc\xa7\xbf\xe4\xf6\xf1\xfc\xe0");
|
|
41 |
|
40
|
42 |
|
|
43 |
// OTHER DEFINITIONS
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
// ============================= LOCAL FUNCTIONS ===============================
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
52 |
|
|
53 |
// -----------------------------------------------------------------------------
|
|
54 |
// CSmsAdapterMsvApi::NewL
|
|
55 |
// -----------------------------------------------------------------------------
|
|
56 |
//
|
|
57 |
CSmsAdapterMsvApi* CSmsAdapterMsvApi::NewL()
|
|
58 |
{
|
|
59 |
CSmsAdapterMsvApi* self = new( ELeave ) CSmsAdapterMsvApi;
|
|
60 |
CleanupStack::PushL( self );
|
|
61 |
self->ConstructL();
|
|
62 |
CleanupStack::Pop( self );
|
|
63 |
return self;
|
|
64 |
}
|
|
65 |
|
|
66 |
// -----------------------------------------------------------------------------
|
|
67 |
// CSmsAdapterMsvApi::~CSmsAdapterMsvApi()
|
|
68 |
// -----------------------------------------------------------------------------
|
|
69 |
//
|
|
70 |
CSmsAdapterMsvApi::~CSmsAdapterMsvApi()
|
|
71 |
{
|
|
72 |
LOGGER_ENTERFN( "CSmsAdapterMsvApi::~CSmsAdapterMsvApi" );
|
|
73 |
SAFEDELETE( iContactsDb );
|
|
74 |
SAFEDELETE( iMtm );
|
|
75 |
SAFEDELETE( iMtmReg );
|
|
76 |
SAFEDELETE( iSession );
|
|
77 |
LOGGER_LEAVEFN( "CSmsAdapterMsvApi::~CSmsAdapterMsvApi" );
|
|
78 |
}
|
|
79 |
|
|
80 |
// -----------------------------------------------------------------------------
|
|
81 |
// CSmsAdapterMsvApi::CSmsAdapterMsvApi
|
|
82 |
// -----------------------------------------------------------------------------
|
|
83 |
//
|
|
84 |
CSmsAdapterMsvApi::CSmsAdapterMsvApi()
|
|
85 |
{
|
|
86 |
}
|
|
87 |
|
|
88 |
// -----------------------------------------------------------------------------
|
|
89 |
// CSmsAdapterMsvApi::ConstructL
|
|
90 |
// -----------------------------------------------------------------------------
|
|
91 |
//
|
|
92 |
void CSmsAdapterMsvApi::ConstructL()
|
|
93 |
{
|
|
94 |
LOGGER_ENTERFN( "CSmsAdapterMsvApi::ConstructL" );
|
|
95 |
|
|
96 |
iSession = CMsvSession::OpenSyncL( *this );
|
|
97 |
iMtmReg = CClientMtmRegistry::NewL( *iSession );
|
|
98 |
iMtm = static_cast<CSmsClientMtm*>( iMtmReg->NewMtmL(KUidMsgTypeSMS) );
|
|
99 |
|
|
100 |
iFs = iSession->FileSession();
|
|
101 |
iMessageDrive = MessageServer::CurrentDriveL( iFs );
|
|
102 |
|
|
103 |
iContactsDb = CContactDatabase::OpenL();
|
|
104 |
|
|
105 |
LOGGER_LEAVEFN( "CSmsAdapterMsvApi::ConstructL" );
|
|
106 |
}
|
|
107 |
|
|
108 |
// -----------------------------------------------------------------------------
|
|
109 |
// CSmsAdapterMsvApi::AddSML
|
|
110 |
// -----------------------------------------------------------------------------
|
|
111 |
//
|
|
112 |
void CSmsAdapterMsvApi::AddSML(
|
|
113 |
CVMessageParser& aSm,
|
|
114 |
TMsvId aFolder,
|
|
115 |
TMsvId& aSmId )
|
|
116 |
{
|
|
117 |
LOGGER_ENTERFN( "CSmsAdapterMsvApi::AddSML" );
|
|
118 |
|
|
119 |
if (!ValidFolderL( aFolder ))
|
|
120 |
{
|
|
121 |
LOGGER_WRITE( "AddSML: wrong folder" );
|
|
122 |
User::Leave( KErrArgument );
|
|
123 |
}
|
|
124 |
|
|
125 |
// Set first default flags
|
|
126 |
TMsvEntry newEntry;
|
|
127 |
newEntry.iType = KUidMsvMessageEntry;
|
|
128 |
newEntry.iServiceId = KMsvLocalServiceIndexEntryId;
|
|
129 |
newEntry.iMtm = KUidMsgTypeSMS;
|
|
130 |
newEntry.SetVisible(EFalse);
|
|
131 |
newEntry.SetInPreparation(ETrue);
|
|
132 |
|
|
133 |
// Create new message entry
|
|
134 |
CMsvEntry* entry = iSession->GetEntryL( aFolder );
|
|
135 |
CleanupStack::PushL( entry );
|
|
136 |
entry->CreateL( newEntry );
|
|
137 |
aSmId = newEntry.Id();
|
|
138 |
entry->SetEntryL(newEntry.Id());
|
|
139 |
|
|
140 |
// Create message header
|
|
141 |
|
|
142 |
CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL();
|
|
143 |
CleanupStack::PushL( paraFormatLayer );
|
|
144 |
CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL();
|
|
145 |
CleanupStack::PushL( charFormatLayer );
|
|
146 |
CRichText* richText = CRichText::NewL( paraFormatLayer, charFormatLayer );
|
|
147 |
CleanupStack::PushL( richText );
|
|
148 |
|
|
149 |
CSmsPDU::TSmsPDUType pduType;
|
|
150 |
|
|
151 |
if (aFolder == KMsvGlobalInBoxIndexEntryId)
|
|
152 |
{
|
|
153 |
pduType = CSmsPDU::ESmsDeliver;
|
|
154 |
}
|
|
155 |
else if (aFolder == KMsvGlobalOutBoxIndexEntryId ||
|
|
156 |
aFolder == KMsvDraftEntryId ||
|
|
157 |
aFolder == KMsvSentEntryId)
|
|
158 |
{
|
|
159 |
pduType = CSmsPDU::ESmsSubmit;
|
|
160 |
}
|
|
161 |
else if (aSm.iRecipients.Count() > 0)
|
|
162 |
{
|
|
163 |
pduType = CSmsPDU::ESmsSubmit;
|
|
164 |
}
|
|
165 |
else
|
|
166 |
{
|
|
167 |
pduType = CSmsPDU::ESmsDeliver;
|
|
168 |
}
|
|
169 |
|
|
170 |
CSmsHeader* smsHeader = CSmsHeader::NewL( pduType, *richText );
|
|
171 |
CleanupStack::PushL( smsHeader );
|
|
172 |
|
|
173 |
// Set the message header in the entry's store
|
|
174 |
CMsvStore* store = entry->EditStoreL();
|
|
175 |
CleanupStack::PushL( store );
|
|
176 |
smsHeader->StoreL( *store );
|
|
177 |
store->StoreBodyTextL( *richText );
|
|
178 |
store->CommitL();
|
|
179 |
|
|
180 |
CleanupStack::PopAndDestroy( store );
|
|
181 |
CleanupStack::PopAndDestroy( smsHeader );
|
|
182 |
CleanupStack::PopAndDestroy( richText );
|
|
183 |
CleanupStack::PopAndDestroy( charFormatLayer );
|
|
184 |
CleanupStack::PopAndDestroy( paraFormatLayer );
|
|
185 |
CleanupStack::PopAndDestroy( entry );
|
|
186 |
|
|
187 |
DoUpdateSML( aSmId, aSm, ETrue );
|
|
188 |
LOGGER_LEAVEFN( "CSmsAdapterMsvApi::AddSML" );
|
|
189 |
}
|
|
190 |
|
|
191 |
// -----------------------------------------------------------------------------
|
|
192 |
// CSmsAdapterMsvApi::ReplaceSML
|
|
193 |
// -----------------------------------------------------------------------------
|
|
194 |
//
|
|
195 |
void CSmsAdapterMsvApi::ReplaceSML( TMsvId aSmId, CVMessageParser& aSm )
|
|
196 |
{
|
|
197 |
LOGGER_ENTERFN( "CSmsAdapterMsvApi::ReplaceSML" );
|
|
198 |
DoUpdateSML( aSmId, aSm, EFalse );
|
|
199 |
LOGGER_LEAVEFN( "CSmsAdapterMsvApi::ReplaceSML" );
|
|
200 |
}
|
|
201 |
|
|
202 |
// -----------------------------------------------------------------------------
|
|
203 |
// CSmsAdapterMsvApi::DeleteSML
|
|
204 |
// -----------------------------------------------------------------------------
|
|
205 |
//
|
|
206 |
void CSmsAdapterMsvApi::DeleteSML( TMsvId aSmId )
|
|
207 |
{
|
|
208 |
LOGGER_ENTERFN( "CSmsAdapterMsvApi::DeleteSML" );
|
|
209 |
|
|
210 |
iMtm->SwitchCurrentEntryL( aSmId );
|
|
211 |
|
|
212 |
TMsvEntry tEntry = iMtm->Entry().Entry();
|
|
213 |
if (tEntry.iType != KUidMsvMessageEntry || tEntry.iMtm != KUidMsgTypeSMS)
|
|
214 |
{
|
|
215 |
LOGGER_WRITE( "Not SMS entry" );
|
|
216 |
User::Leave(KErrNotSupported);
|
|
217 |
}
|
|
218 |
|
|
219 |
iMtm->SwitchCurrentEntryL( tEntry.Parent() );
|
|
220 |
iMtm->Entry().DeleteL( aSmId );
|
|
221 |
LOGGER_LEAVEFN( "CSmsAdapterMsvApi::DeleteSML" );
|
|
222 |
}
|
|
223 |
|
|
224 |
// -----------------------------------------------------------------------------
|
|
225 |
// CSmsAdapterMsvApi::DeleteUserFolderL
|
|
226 |
// -----------------------------------------------------------------------------
|
|
227 |
//
|
|
228 |
TInt CSmsAdapterMsvApi::DeleteUserFolderL( TMsvId aUid )
|
|
229 |
{
|
|
230 |
LOGGER_ENTERFN( "CSmsAdapterMsvApi::DeleteUserFolderL" );
|
|
231 |
|
|
232 |
iMtm->SwitchCurrentEntryL( aUid );
|
|
233 |
CMsvEntry& entry = iMtm->Entry();
|
|
234 |
TMsvEntry tEntry = entry.Entry();
|
|
235 |
|
|
236 |
if (tEntry.iType != KUidMsvFolderEntry || tEntry.Parent() != KMsvMyFoldersEntryIdValue)
|
|
237 |
{
|
|
238 |
LOGGER_WRITE( "Not correct folder" );
|
|
239 |
User::Leave(KErrNotSupported);
|
|
240 |
}
|
|
241 |
|
|
242 |
CMsvEntrySelection* children = entry.ChildrenL();
|
|
243 |
TInt count = children->Count();
|
|
244 |
delete children;
|
|
245 |
|
|
246 |
if (count > 0)
|
|
247 |
{
|
|
248 |
LOGGER_WRITE( "Folder not empty" );
|
|
249 |
return KErrInUse;
|
|
250 |
}
|
|
251 |
|
|
252 |
tEntry.SetReadOnly(EFalse);
|
|
253 |
entry.ChangeL( tEntry );
|
|
254 |
|
|
255 |
iMtm->SwitchCurrentEntryL( tEntry.Parent() );
|
|
256 |
iMtm->Entry().DeleteL( aUid );
|
|
257 |
|
|
258 |
LOGGER_LEAVEFN( "CSmsAdapterMsvApi::DeleteUserFolderL" );
|
|
259 |
return KErrNone;
|
|
260 |
}
|
|
261 |
|
|
262 |
// -----------------------------------------------------------------------------
|
|
263 |
// CSmsAdapterMsvApi::RetrieveSML
|
|
264 |
// -----------------------------------------------------------------------------
|
|
265 |
//
|
|
266 |
void CSmsAdapterMsvApi::RetrieveSML(
|
|
267 |
TMsvId aSmId,
|
|
268 |
TMsvId& aParent,
|
|
269 |
CVMessageParser& aSm,
|
|
270 |
TBool& aUnread)
|
|
271 |
{
|
|
272 |
LOGGER_ENTERFN( "CSmsAdapterMsvApi::RetrieveSML" );
|
|
273 |
|
|
274 |
iMtm->SwitchCurrentEntryL( aSmId );
|
|
275 |
iMtm->LoadMessageL();
|
|
276 |
|
|
277 |
CRichText& mtmBody = iMtm->Body();
|
|
278 |
aSm.StoreMessageBodyL( mtmBody );
|
|
279 |
|
|
280 |
TMsvEntry tEntry = iMtm->Entry().Entry();
|
|
281 |
|
|
282 |
aUnread = tEntry.Unread();
|
|
283 |
if (aUnread)
|
|
284 |
{
|
|
285 |
aSm.iStatus = KVMsgStatusUnread;
|
|
286 |
}
|
|
287 |
else
|
|
288 |
{
|
|
289 |
aSm.iStatus = KVMsgStatusRead;
|
|
290 |
}
|
|
291 |
|
|
292 |
aSm.iUniversalTime = tEntry.iDate;
|
|
293 |
aSm.iHomeTime = HomeTimeFromUniversalTime( aSm.iUniversalTime );
|
|
294 |
|
|
295 |
aParent = tEntry.Parent();
|
|
296 |
switch (aParent)
|
|
297 |
{
|
|
298 |
case KMsvGlobalInBoxIndexEntryId:
|
|
299 |
aSm.iFolder = KFolderInbox;
|
|
300 |
break;
|
|
301 |
case KMsvGlobalOutBoxIndexEntryId:
|
|
302 |
aSm.iFolder = KFolderOutbox;
|
|
303 |
break;
|
|
304 |
case KMsvDraftEntryId:
|
|
305 |
aSm.iFolder = KFolderDraft;
|
|
306 |
break;
|
|
307 |
case KMsvSentEntryId:
|
|
308 |
aSm.iFolder = KFolderSent;
|
|
309 |
break;
|
|
310 |
case KMsvMyFoldersEntryIdValue:
|
|
311 |
aSm.iFolder = KFolderMyFolders;
|
|
312 |
break;
|
|
313 |
default:
|
|
314 |
TPtrC folderName;
|
|
315 |
TTime time;
|
|
316 |
TBool found = FindUserFolderL(aParent, folderName, time);
|
|
317 |
if (found && folderName.Length() <= KMaxFolderNameLength)
|
|
318 |
{
|
|
319 |
aSm.iFolder = folderName;
|
|
320 |
}
|
|
321 |
else
|
|
322 |
{
|
|
323 |
LOGGER_WRITE_1( "Not folder name found for folder: %d", aParent );
|
|
324 |
}
|
|
325 |
}
|
|
326 |
LOG( aSm.iFolder );
|
|
327 |
|
|
328 |
const CSmsHeader& smsHeader = iMtm->SmsHeader();
|
|
329 |
|
|
330 |
if ( smsHeader.Type() == CSmsPDU::ESmsDeliver )
|
|
331 |
{
|
|
332 |
TPtrC fromAddr = smsHeader.FromAddress();
|
|
333 |
aSm.ParseTelephoneNumber( fromAddr, aSm.iSender );
|
|
334 |
}
|
|
335 |
else
|
|
336 |
{
|
|
337 |
const CMsvRecipientList& recipients = iMtm->AddresseeList();
|
|
338 |
for (TInt i = 0; i < recipients.Count(); i++)
|
|
339 |
{
|
|
340 |
CVMessageParser::TTelephoneNumber recipientInfo;
|
|
341 |
aSm.ParseTelephoneNumber( recipients[i], recipientInfo );
|
64
|
342 |
aSm.iRecipients.AppendL( recipientInfo );
|
40
|
343 |
}
|
|
344 |
}
|
|
345 |
|
|
346 |
LOGGER_LEAVEFN( "CSmsAdapterMsvApi::RetrieveSML" );
|
|
347 |
}
|
|
348 |
|
|
349 |
// -----------------------------------------------------------------------------
|
|
350 |
// CSmsAdapterMsvApi::SendSML
|
|
351 |
// -----------------------------------------------------------------------------
|
|
352 |
//
|
|
353 |
void CSmsAdapterMsvApi::SendSML( TMsvId aSmId )
|
|
354 |
{
|
|
355 |
LOGGER_ENTERFN( "CSmsAdapterMsvApi::SendSML" );
|
|
356 |
|
|
357 |
iMtm->SwitchCurrentEntryL( aSmId );
|
|
358 |
|
|
359 |
TMsvEntry msvEntry = iMtm->Entry().Entry();
|
|
360 |
|
|
361 |
if (msvEntry.Parent() != KMsvGlobalOutBoxIndexEntryId)
|
|
362 |
{
|
|
363 |
LOGGER_WRITE_1( "Wrong folder, parent: %d", msvEntry.Parent() );
|
|
364 |
return;
|
|
365 |
}
|
|
366 |
|
|
367 |
iMtm->LoadMessageL();
|
|
368 |
|
|
369 |
msvEntry.SetInPreparation( EFalse );
|
|
370 |
msvEntry.SetSendingState( KMsvSendStateWaiting );
|
|
371 |
msvEntry.iDate.UniversalTime();
|
|
372 |
|
|
373 |
iMtm->RestoreServiceAndSettingsL();
|
|
374 |
CSmsHeader& header = iMtm->SmsHeader();
|
|
375 |
|
|
376 |
CSmsSettings* sendOptions = CSmsSettings::NewL();
|
|
377 |
CleanupStack::PushL( sendOptions );
|
|
378 |
|
|
379 |
sendOptions->CopyL( iMtm->ServiceSettings() );
|
|
380 |
sendOptions->SetDelivery( ESmsDeliveryImmediately );
|
|
381 |
|
|
382 |
TSmsDataCodingScheme::TSmsAlphabet dataCoding = TSmsDataCodingScheme::ESmsAlphabet7Bit;
|
|
383 |
CRichText& msgBody = iMtm->Body();
|
|
384 |
HBufC* msgBodyBuf = HBufC::NewLC( msgBody.DocumentLength() );
|
|
385 |
TPtr16 ptrBody = msgBodyBuf->Des();
|
|
386 |
msgBody.Extract( ptrBody, 0, msgBody.DocumentLength() );
|
|
387 |
LOG(ptrBody);
|
|
388 |
|
|
389 |
for (TInt i = 0; i < ptrBody.Length(); i++)
|
|
390 |
{
|
|
391 |
if (IsUnicode( ptrBody[i] ))
|
|
392 |
{
|
|
393 |
LOGGER_WRITE_1( "Character %d is unicode", i );
|
|
394 |
dataCoding = TSmsDataCodingScheme::ESmsAlphabetUCS2;
|
|
395 |
break;
|
|
396 |
}
|
|
397 |
}
|
|
398 |
|
|
399 |
sendOptions->SetCharacterSet( dataCoding );
|
|
400 |
CleanupStack::PopAndDestroy( msgBodyBuf );
|
|
401 |
|
|
402 |
header.SetSmsSettingsL( *sendOptions );
|
|
403 |
if( header.Message().ServiceCenterAddress().Length() == 0 )
|
|
404 |
{
|
|
405 |
LOGGER_WRITE( "header.Message().ServiceCenterAddress().Length() == 0" );
|
|
406 |
|
|
407 |
CSmsSettings* serviceSettings = &( iMtm->ServiceSettings() );
|
|
408 |
|
|
409 |
if (!serviceSettings->ServiceCenterCount())
|
|
410 |
{
|
|
411 |
LOGGER_WRITE("Cervice Center not found, could not send message");
|
|
412 |
User::Leave( KErrCompletion );
|
|
413 |
}
|
|
414 |
else
|
|
415 |
{
|
|
416 |
CSmsServiceCenter* sc = &serviceSettings->GetServiceCenter( serviceSettings->DefaultServiceCenter() );
|
|
417 |
header.Message().SetServiceCenterAddressL( sc->Address() );
|
|
418 |
}
|
|
419 |
}
|
|
420 |
|
|
421 |
const CMsvRecipientList& addrList = iMtm->AddresseeList();
|
|
422 |
if ( addrList.Count() == 0 )
|
|
423 |
{
|
|
424 |
LOGGER_WRITE( "SendSML: no recipient" );
|
|
425 |
User::Leave( KErrGeneral );
|
|
426 |
}
|
|
427 |
|
|
428 |
CMsvEntry* entry = &( iMtm->Entry() );
|
|
429 |
entry->ChangeL( msvEntry );
|
|
430 |
iMtm->SaveMessageL();
|
|
431 |
|
|
432 |
CMsvEntrySelection* sel = new (ELeave) CMsvEntrySelection;
|
|
433 |
CleanupStack::PushL( sel );
|
|
434 |
sel->AppendL( entry->EntryId() );
|
|
435 |
|
|
436 |
TBuf8<1> dummy;
|
|
437 |
CMsvOperationActiveSchedulerWait* waiter = CMsvOperationActiveSchedulerWait::NewLC();
|
|
438 |
waiter->iStatus = KRequestPending;
|
|
439 |
CMsvOperation* op = iMtm->InvokeAsyncFunctionL( ESmsMtmCommandScheduleCopy, *sel, dummy, waiter->iStatus );
|
|
440 |
CleanupStack::PushL( op );
|
|
441 |
waiter->Start();
|
|
442 |
|
|
443 |
LOGGER_WRITE_1( "InvokeAsyncFunctionL: status %d", waiter->iStatus.Int());
|
|
444 |
|
|
445 |
CleanupStack::PopAndDestroy( 4 ); // op, waiter, sel, sendOptions
|
|
446 |
|
|
447 |
LOGGER_LEAVEFN( "CSmsAdapterMsvApi::SendSML" );
|
|
448 |
}
|
|
449 |
|
|
450 |
// -----------------------------------------------------------------------------
|
|
451 |
// CSmsAdapterMsvApi::HandleSessionEventL
|
|
452 |
// -----------------------------------------------------------------------------
|
|
453 |
//
|
|
454 |
void CSmsAdapterMsvApi::HandleSessionEventL( TMsvSessionEvent aEvent, TAny*, TAny*, TAny* )
|
|
455 |
{
|
|
456 |
LOGGER_WRITE_1( "CSmsAdapterMsvApi::HandleSessionEventL: %d", aEvent);
|
|
457 |
|
|
458 |
switch ( aEvent )
|
|
459 |
{
|
|
460 |
case EMsvCloseSession: // The client should immediately close the session with the Message Server.
|
|
461 |
case EMsvServerTerminated: // The Message Server has been terminated.
|
|
462 |
// All clients must close their sessions immediately.
|
|
463 |
{
|
|
464 |
if (iSession)
|
|
465 |
{
|
|
466 |
SAFEDELETE( iMtm );
|
|
467 |
SAFEDELETE( iMtmReg );
|
|
468 |
SAFEDELETE( iSession );
|
|
469 |
}
|
|
470 |
}
|
|
471 |
break;
|
|
472 |
|
|
473 |
default:
|
|
474 |
// Nothing is done
|
|
475 |
break;
|
|
476 |
}
|
|
477 |
}
|
|
478 |
|
|
479 |
// -----------------------------------------------------------------------------
|
|
480 |
// CSmsAdapterMsvApi::MsvSession
|
|
481 |
// -----------------------------------------------------------------------------
|
|
482 |
//
|
|
483 |
CMsvSession* CSmsAdapterMsvApi::MsvSessionL()
|
|
484 |
{
|
|
485 |
if (!iSession)
|
|
486 |
{
|
|
487 |
User::Leave( KErrGeneral );
|
|
488 |
}
|
|
489 |
return iSession;
|
|
490 |
}
|
|
491 |
|
|
492 |
// -----------------------------------------------------------------------------
|
|
493 |
// CSmsAdapterMsvApi::CleanFolderGetMsvIdsL
|
|
494 |
// -----------------------------------------------------------------------------
|
|
495 |
//
|
|
496 |
CMsvEntrySelection* CSmsAdapterMsvApi::CleanFolderGetMsvIdsL(TMsvId aFolderId)
|
|
497 |
{
|
|
498 |
LOGGER_ENTERFN( "CMsvEntrySelection::CleanFolderGetMsvIdsL" );
|
|
499 |
|
|
500 |
CMsvEntry* cEntry = iSession->GetEntryL( KMsvRootIndexEntryId );
|
|
501 |
CleanupStack::PushL( cEntry );
|
|
502 |
|
|
503 |
cEntry->SetEntryL( aFolderId );
|
|
504 |
cEntry->SetSortTypeL( TMsvSelectionOrdering( KMsvNoGrouping, EMsvSortByNone, EFalse ) );
|
|
505 |
CMsvEntrySelection* msvEntrySelection = cEntry->ChildrenWithMtmL( KUidMsgTypeSMS );
|
|
506 |
|
|
507 |
CleanupStack::PopAndDestroy( cEntry );
|
|
508 |
CleanupStack::PushL( msvEntrySelection );
|
|
509 |
|
|
510 |
for (TInt i = 0; i < msvEntrySelection->Count(); i++)
|
|
511 |
{
|
|
512 |
CMsvEntry* entry = iSession->GetEntryL( msvEntrySelection->At(i) );
|
|
513 |
CleanupStack::PushL( entry );
|
|
514 |
TMsvEntry tEntry = entry->Entry();
|
|
515 |
tEntry.SetReadOnly( EFalse );
|
|
516 |
entry->ChangeL( tEntry );
|
|
517 |
DeleteSML( msvEntrySelection->At(i) );
|
|
518 |
CleanupStack::PopAndDestroy(); //entry
|
|
519 |
}
|
|
520 |
|
|
521 |
CleanupStack::Pop(msvEntrySelection);
|
|
522 |
LOGGER_LEAVEFN( "CSmsAdapterMsvApi::CleanFolderGetMsvIdsL" );
|
|
523 |
return msvEntrySelection;
|
|
524 |
}
|
|
525 |
|
|
526 |
// -----------------------------------------------------------------------------
|
|
527 |
// CSmsAdapterMsvApi::CleanFolderL
|
|
528 |
// -----------------------------------------------------------------------------
|
|
529 |
//
|
|
530 |
void CSmsAdapterMsvApi::CleanFolderL(TMsvId aFolderId)
|
|
531 |
{
|
|
532 |
CMsvEntrySelection* msvEntrySelection = CleanFolderGetMsvIdsL(aFolderId);
|
|
533 |
delete msvEntrySelection;
|
|
534 |
}
|
|
535 |
|
|
536 |
// -----------------------------------------------------------------------------
|
|
537 |
// CSmsAdapterMsvApi::CleanUserFoldersL
|
|
538 |
// Cleans all user folders from SMS messages
|
|
539 |
// -----------------------------------------------------------------------------
|
|
540 |
void CSmsAdapterMsvApi::CleanUserFoldersL()
|
|
541 |
{
|
|
542 |
LOGGER_ENTERFN( "CSmsAdapterMsvApi::CleanUserFoldersL" );
|
|
543 |
|
|
544 |
// Get the folder
|
|
545 |
CMsvEntry* msvEntry = iSession->GetEntryL(KMsvMyFoldersEntryIdValue);
|
|
546 |
CleanupStack::PushL(msvEntry);
|
|
547 |
|
|
548 |
// Find all of it's childs
|
|
549 |
CMsvEntrySelection* folders = msvEntry->ChildrenWithTypeL(KUidMsvFolderEntry);
|
|
550 |
CleanupStack::PopAndDestroy(msvEntry);
|
|
551 |
CleanupStack::PushL(folders);
|
|
552 |
|
|
553 |
TInt error(KErrNone);
|
|
554 |
|
|
555 |
for (TInt index = 0; index < folders->Count(); index++)
|
|
556 |
{
|
|
557 |
TMsvId folderId = folders->At(index);
|
|
558 |
|
|
559 |
if (folderId != KMsvMyFoldersTemplatesFolderId)
|
|
560 |
{
|
|
561 |
CleanFolderL(folderId);
|
|
562 |
error = DeleteUserFolderL(folderId);
|
|
563 |
if (error != KErrNone)
|
|
564 |
{
|
|
565 |
// Note: folder is not deleted if contains other message items (like MMS)
|
|
566 |
// In this case DeleteUserFolderL returns KErrInUse.
|
|
567 |
LOGGER_WRITE_1("iMsvApi->DeleteUserFolderL failed with %d", error);
|
|
568 |
}
|
|
569 |
}
|
|
570 |
}
|
|
571 |
|
|
572 |
CleanupStack::PopAndDestroy(folders);
|
|
573 |
|
|
574 |
// Delete also SMS messages directly under My Folders
|
|
575 |
CleanFolderL(KMsvMyFoldersEntryIdValue);
|
|
576 |
LOGGER_LEAVEFN( "CSmsAdapterMsvApi::CleanUserFoldersL" );
|
|
577 |
}
|
|
578 |
|
|
579 |
// -----------------------------------------------------------------------------
|
|
580 |
// CSmsAdapterMsvApi::DiskSpaceBelowCriticalLevelL
|
|
581 |
// -----------------------------------------------------------------------------
|
|
582 |
//
|
|
583 |
TBool CSmsAdapterMsvApi::DiskSpaceBelowCriticalLevelL( TInt aDataSize )
|
|
584 |
{
|
|
585 |
return SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, aDataSize, iMessageDrive );
|
|
586 |
}
|
|
587 |
|
|
588 |
// -----------------------------------------------------------------------------
|
|
589 |
// CSmsAdapterMsvApi::UpdateSMStatusL
|
|
590 |
// -----------------------------------------------------------------------------
|
|
591 |
//
|
|
592 |
void CSmsAdapterMsvApi::UpdateSMStatusL( TMsvId aSmId, CVMessageParser &aSm )
|
|
593 |
{
|
|
594 |
LOGGER_ENTERFN( "CSmsAdapterMsvApi::UpdateSMStatusL" );
|
|
595 |
|
|
596 |
iMtm->SwitchCurrentEntryL( aSmId );
|
|
597 |
|
|
598 |
CMsvEntry& msvEntry = iMtm->Entry();
|
|
599 |
const TMsvEntry& oldEntry = msvEntry.Entry();
|
|
600 |
|
|
601 |
TMsvEntry newEntry( oldEntry );
|
|
602 |
|
|
603 |
// STATUS
|
|
604 |
if (aSm.iStatus.Compare( KVMsgStatusUnread ) == 0)
|
|
605 |
{
|
|
606 |
newEntry.SetUnread( ETrue );
|
|
607 |
}
|
|
608 |
else if (aSm.iStatus.Compare( KVMsgStatusRead ) == 0)
|
|
609 |
{
|
|
610 |
newEntry.SetUnread( EFalse );
|
|
611 |
}
|
|
612 |
else
|
|
613 |
{
|
|
614 |
LOGGER_WRITE( "Unexpected status, not updated" );
|
|
615 |
LOG( aSm.iStatus );
|
|
616 |
}
|
|
617 |
|
|
618 |
msvEntry.ChangeL( newEntry );
|
|
619 |
LOGGER_LEAVEFN( "CSmsAdapterMsvApi::UpdateSMStatusL" );
|
|
620 |
}
|
|
621 |
|
|
622 |
// -----------------------------------------------------------------------------
|
|
623 |
// CSmsAdapterMsvApi::DoUpdateSML
|
|
624 |
// -----------------------------------------------------------------------------
|
|
625 |
//
|
|
626 |
void CSmsAdapterMsvApi::DoUpdateSML( TMsvId aSmId, CVMessageParser &aSm, TBool aNewSm )
|
|
627 |
{
|
|
628 |
LOGGER_WRITE_1( "CSmsAdapterMsvApi::DoUpdateSML: %d", aSmId );
|
|
629 |
TInt i;
|
|
630 |
|
|
631 |
iMtm->SwitchCurrentEntryL( aSmId );
|
|
632 |
iMtm->LoadMessageL();
|
|
633 |
CMsvEntry& msvEntry = iMtm->Entry();
|
|
634 |
const TMsvEntry& oldEntry = msvEntry.Entry();
|
|
635 |
TMsvEntry newEntry(oldEntry);
|
|
636 |
|
|
637 |
// Set message status
|
|
638 |
if (aSm.iStatus.Compare( KVMsgStatusUnread ) == 0)
|
|
639 |
{
|
|
640 |
newEntry.SetUnread( ETrue );
|
|
641 |
}
|
|
642 |
else if (aSm.iStatus.Compare( KVMsgStatusRead ) == 0)
|
|
643 |
{
|
|
644 |
newEntry.SetUnread( EFalse );
|
|
645 |
}
|
|
646 |
else if (aNewSm)
|
|
647 |
{
|
|
648 |
newEntry.SetUnread( EFalse ); // by default msg is not unread, if we don't know
|
|
649 |
}
|
|
650 |
|
|
651 |
// Set time. store format is universal
|
|
652 |
if ( aSm.iUniversalTime.Int64() > 0 )
|
|
653 |
{
|
|
654 |
newEntry.iDate = aSm.iUniversalTime;
|
|
655 |
}
|
|
656 |
else if ( aSm.iHomeTime.Int64() > 0 )
|
|
657 |
{
|
|
658 |
newEntry.iDate = UniversalTimeFromHomeTime( aSm.iHomeTime );
|
|
659 |
}
|
|
660 |
else
|
|
661 |
{
|
|
662 |
newEntry.iDate.UniversalTime();
|
|
663 |
}
|
|
664 |
|
|
665 |
// ADDRESS INFORMATION
|
|
666 |
TMsvId parent = newEntry.Parent();
|
|
667 |
LOGGER_WRITE_1( "Parent is %d", parent );
|
|
668 |
|
|
669 |
TBuf<KNameMaxLength> addrBookName;
|
|
670 |
|
|
671 |
CSmsHeader& header = iMtm->SmsHeader();
|
|
672 |
|
|
673 |
if (header.Type() == CSmsPDU::ESmsDeliver)
|
|
674 |
{
|
|
675 |
if (aSm.iSender.iName.Length() > 0)
|
|
676 |
{
|
|
677 |
newEntry.iDetails.Set( aSm.iSender.iName );
|
|
678 |
header.SetFromAddressL( aSm.iSender.iName );
|
|
679 |
}
|
|
680 |
else if (aSm.iSender.iNumber.Length() > 0)
|
|
681 |
{
|
|
682 |
FetchNameFromContactsL(aSm.iSender.iNumber, addrBookName);
|
|
683 |
if (addrBookName.Length() > 0)
|
|
684 |
{
|
|
685 |
newEntry.iDetails.Set( addrBookName );
|
|
686 |
header.SetFromAddressL( addrBookName );
|
64
|
687 |
|
40
|
688 |
}
|
|
689 |
else
|
|
690 |
{
|
|
691 |
newEntry.iDetails.Set( aSm.iSender.iNumber );
|
|
692 |
header.SetFromAddressL( aSm.iSender.iNumber );
|
|
693 |
}
|
|
694 |
}
|
|
695 |
CSmsMessage& smsMsg = header.Message();
|
|
696 |
CSmsPDU& smsPdu = smsMsg.SmsPDU();
|
|
697 |
CSmsDeliver* smsDeliver = reinterpret_cast<CSmsDeliver*>( &smsPdu );
|
|
698 |
smsDeliver->SetServiceCenterTimeStamp( newEntry.iDate );
|
64
|
699 |
if (aSm.iSender.iNumber.Length() > 0)
|
|
700 |
{
|
|
701 |
TGsmSmsTelNumber telNum;
|
|
702 |
telNum.iTelNumber.Copy( aSm.iSender.iNumber );
|
|
703 |
smsDeliver->SetParsedToFromAddressL( telNum );
|
|
704 |
}
|
40
|
705 |
}
|
|
706 |
else // message to be sent
|
|
707 |
{
|
|
708 |
if (!aNewSm)
|
|
709 |
{
|
|
710 |
const CMsvRecipientList& addrList = iMtm->AddresseeList();
|
|
711 |
TInt numOldAddr = addrList.Count();
|
|
712 |
for (i = 0; i < numOldAddr; i++)
|
|
713 |
{
|
|
714 |
iMtm->RemoveAddressee( i );
|
|
715 |
}
|
|
716 |
}
|
|
717 |
|
|
718 |
TInt numRecipients = aSm.iRecipients.Count();
|
|
719 |
|
|
720 |
if (numRecipients > 0)
|
|
721 |
{
|
|
722 |
if (aSm.iRecipients[0].iName.Length() > 0)
|
|
723 |
{
|
|
724 |
newEntry.iDetails.Set( aSm.iRecipients[0].iName );
|
|
725 |
}
|
|
726 |
else if (aSm.iRecipients[0].iNumber.Length() > 0)
|
|
727 |
{
|
|
728 |
FetchNameFromContactsL(aSm.iRecipients[0].iNumber, addrBookName);
|
|
729 |
if (addrBookName.Length() > 0)
|
|
730 |
{
|
|
731 |
newEntry.iDetails.Set( addrBookName );
|
|
732 |
}
|
|
733 |
else
|
|
734 |
{
|
|
735 |
newEntry.iDetails.Set( aSm.iRecipients[0].iNumber );
|
|
736 |
}
|
|
737 |
}
|
|
738 |
}
|
|
739 |
|
|
740 |
for (i = 0; i < numRecipients; i++)
|
|
741 |
{
|
|
742 |
if (aSm.iRecipients[i].iNumber.Length() > 0)
|
|
743 |
{
|
|
744 |
if (aSm.iRecipients[i].iName.Length() > 0)
|
|
745 |
{
|
|
746 |
iMtm->AddAddresseeL( aSm.iRecipients[i].iNumber, aSm.iRecipients[i].iName );
|
|
747 |
}
|
|
748 |
else
|
|
749 |
{
|
|
750 |
FetchNameFromContactsL( aSm.iRecipients[i].iNumber, addrBookName );
|
|
751 |
iMtm->AddAddresseeL( aSm.iRecipients[i].iNumber, addrBookName );
|
|
752 |
}
|
|
753 |
}
|
|
754 |
}
|
|
755 |
} // else
|
|
756 |
|
|
757 |
// MESSAGE BODY
|
|
758 |
LOGGER_WRITE( "Add message body" );
|
|
759 |
CRichText& mtmBody = iMtm->Body();
|
|
760 |
mtmBody.Reset();
|
|
761 |
aSm.LoadMessageBodyL( mtmBody );
|
|
762 |
|
|
763 |
TBuf<KSmsDescriptionLength> description;
|
|
764 |
description.Zero();
|
|
765 |
if (aSm.iMessageBody)
|
|
766 |
{
|
|
767 |
TPtrC16 leftBody = aSm.iMessageBody->Left( KSmsDescriptionLength );
|
|
768 |
description.Copy( leftBody );
|
|
769 |
|
|
770 |
for (i = 0; i < description.Length(); i++)
|
|
771 |
{
|
|
772 |
if (description[i] == '\n' || description[i] == '\r')
|
|
773 |
{
|
|
774 |
description[i] = ' ';
|
|
775 |
}
|
|
776 |
}
|
|
777 |
newEntry.iDescription.Set( description );
|
|
778 |
}
|
|
779 |
|
|
780 |
newEntry.SetVisible( ETrue );
|
|
781 |
newEntry.SetComplete( ETrue );
|
|
782 |
newEntry.SetInPreparation( EFalse );
|
|
783 |
newEntry.SetSendingState( KMsvSendStateUponRequest );
|
|
784 |
|
|
785 |
msvEntry.ChangeL( newEntry );
|
|
786 |
|
|
787 |
LOGGER_WRITE( "Save message" );
|
|
788 |
iMtm->SaveMessageL();
|
|
789 |
|
|
790 |
LOGGER_LEAVEFN( "CSmsAdapterMsvApi::DoUpdateSML" );
|
|
791 |
}
|
|
792 |
|
|
793 |
// -----------------------------------------------------------------------------
|
|
794 |
// CSmsAdapterMsvApi::ValidUserFolder
|
|
795 |
// -----------------------------------------------------------------------------
|
|
796 |
//
|
|
797 |
TBool CSmsAdapterMsvApi::ValidFolderL( TMsvId aFolder, TBool aOutboxValid )
|
|
798 |
{
|
|
799 |
TBool valid(EFalse);
|
|
800 |
|
|
801 |
switch ( aFolder )
|
|
802 |
{
|
|
803 |
case KMsvGlobalInBoxIndexEntryId:
|
|
804 |
valid = ETrue;
|
|
805 |
break;
|
|
806 |
case KMsvDraftEntryId:
|
|
807 |
valid = ETrue;
|
|
808 |
break;
|
|
809 |
case KMsvSentEntryId:
|
|
810 |
valid = ETrue;
|
|
811 |
break;
|
|
812 |
case KMsvGlobalOutBoxIndexEntryId:
|
|
813 |
if (aOutboxValid)
|
|
814 |
{
|
|
815 |
valid = ETrue;
|
|
816 |
}
|
|
817 |
break;
|
|
818 |
case KMsvMyFoldersEntryIdValue:
|
|
819 |
valid = ETrue;
|
|
820 |
break;
|
|
821 |
default:
|
|
822 |
valid = FindUserFolderL(aFolder);
|
|
823 |
}
|
|
824 |
|
|
825 |
return valid;
|
|
826 |
}
|
|
827 |
|
|
828 |
// -----------------------------------------------------------------------------
|
|
829 |
// CSmsAdapterMsvApi::FindUserFolderL
|
|
830 |
// -----------------------------------------------------------------------------
|
|
831 |
//
|
|
832 |
TBool CSmsAdapterMsvApi::FindUserFolderL(TMsvId aFolder, TPtrC& aName, TTime& aDate)
|
|
833 |
{
|
|
834 |
TBool found(EFalse);
|
|
835 |
|
|
836 |
CMsvEntry* entry = iSession->GetEntryL( KMsvMyFoldersEntryIdValue );
|
|
837 |
CleanupStack::PushL( entry );
|
|
838 |
|
|
839 |
CMsvEntrySelection* selection = entry->ChildrenL();
|
|
840 |
CleanupStack::PushL( selection );
|
|
841 |
|
|
842 |
TMsvId serviceId;
|
|
843 |
TMsvEntry entryT;
|
|
844 |
|
|
845 |
for( TInt i = 0; i < selection->Count(); i++ )
|
|
846 |
{
|
|
847 |
User::LeaveIfError( iSession->GetEntry( selection->At( i ), serviceId, entryT ) );
|
|
848 |
|
|
849 |
if ( !entryT.Deleted() && entryT.iType == KUidMsvFolderEntry && entryT.Id() == aFolder )
|
|
850 |
{
|
|
851 |
found = ETrue;
|
|
852 |
aDate = entryT.iDate;
|
|
853 |
aName.Set(entryT.iDetails);
|
|
854 |
break;
|
|
855 |
}
|
|
856 |
}
|
|
857 |
|
|
858 |
CleanupStack::PopAndDestroy( 2 ); // entry, selection
|
|
859 |
|
|
860 |
return found;
|
|
861 |
}
|
|
862 |
|
|
863 |
// -----------------------------------------------------------------------------
|
|
864 |
// CSmsAdapterMsvApi::FindUserFolderL
|
|
865 |
// -----------------------------------------------------------------------------
|
|
866 |
//
|
|
867 |
TBool CSmsAdapterMsvApi::FindUserFolderL(TMsvId aFolder)
|
|
868 |
{
|
|
869 |
TPtrC name;
|
|
870 |
TTime time;
|
|
871 |
|
|
872 |
return FindUserFolderL(aFolder, name, time);
|
|
873 |
}
|
|
874 |
|
|
875 |
// -----------------------------------------------------------------------------
|
|
876 |
// CSmsAdapterMsvApi::FindUserFolderL
|
|
877 |
// -----------------------------------------------------------------------------
|
|
878 |
//
|
|
879 |
TBool CSmsAdapterMsvApi::FindUserFolderL(const TDesC& aName, TMsvId& aFolder)
|
|
880 |
{
|
|
881 |
CMsvEntry* entry = iSession->GetEntryL( KMsvMyFoldersEntryIdValue );
|
|
882 |
CleanupStack::PushL( entry );
|
|
883 |
|
|
884 |
CMsvEntrySelection* selection = entry->ChildrenL();
|
|
885 |
CleanupStack::PushL( selection );
|
|
886 |
|
|
887 |
TBool found(EFalse);
|
|
888 |
TMsvId serviceId;
|
|
889 |
TMsvEntry entryT;
|
|
890 |
|
|
891 |
for( TInt i = 0; i < selection->Count(); i++ )
|
|
892 |
{
|
|
893 |
User::LeaveIfError( iSession->GetEntry( selection->At( i ), serviceId, entryT ) );
|
|
894 |
|
|
895 |
if ( !entryT.Deleted() && entryT.iType == KUidMsvFolderEntry &&
|
|
896 |
aName.Compare(entryT.iDescription) == 0 )
|
|
897 |
{
|
|
898 |
found = ETrue;
|
|
899 |
aFolder = entryT.Id();
|
|
900 |
break;
|
|
901 |
}
|
|
902 |
}
|
|
903 |
|
|
904 |
CleanupStack::PopAndDestroy( 2 ); // entry, selection
|
|
905 |
|
|
906 |
return found;
|
|
907 |
}
|
|
908 |
|
|
909 |
// -----------------------------------------------------------------------------
|
|
910 |
// CSmsAdapterMsvApi::IsUnicode
|
|
911 |
// -----------------------------------------------------------------------------
|
|
912 |
//
|
|
913 |
TBool CSmsAdapterMsvApi::IsUnicode( const TUint16 aValue )
|
|
914 |
{
|
|
915 |
if ( aValue > 0x7F && KSmsNonUnicodeChars().Locate( aValue ) < 0 )
|
|
916 |
{
|
|
917 |
LOGGER_WRITE_1( "IsUnicode: Found UC char %d", aValue );
|
|
918 |
return ETrue;
|
|
919 |
}
|
|
920 |
else
|
|
921 |
{
|
|
922 |
return EFalse;
|
|
923 |
}
|
|
924 |
}
|
|
925 |
|
|
926 |
// -----------------------------------------------------------------------------
|
|
927 |
// CSmsAdapterMsvApi::MoveSML
|
|
928 |
// Moves SM to another folder.
|
|
929 |
// -----------------------------------------------------------------------------
|
|
930 |
void CSmsAdapterMsvApi::MoveSML( TMsvId aSmId, TMsvId aParentId )
|
|
931 |
{
|
|
932 |
LOGGER_ENTERFN( "CSmsAdapterMsvApi::MoveSML starts" );
|
|
933 |
|
|
934 |
if ( !ValidFolderL( aParentId ) )
|
|
935 |
{
|
|
936 |
LOGGER_WRITE( "MoveSML: wrong folder" );
|
|
937 |
User::Leave( KErrArgument );
|
|
938 |
}
|
|
939 |
|
|
940 |
// Find the parent
|
|
941 |
CMsvEntry* clientEntry( NULL );
|
|
942 |
|
|
943 |
// Find this entry and put it to cleanup stack
|
|
944 |
clientEntry = iSession->GetEntryL( aSmId );
|
|
945 |
CleanupStack::PushL( clientEntry );
|
|
946 |
|
|
947 |
// Check that this is a SMS message
|
|
948 |
TMsvEntry entryT = clientEntry->Entry();
|
|
949 |
if (entryT.iType != KUidMsvMessageEntry || entryT.iMtm != KUidMsgTypeSMS)
|
|
950 |
{
|
|
951 |
LOGGER_WRITE( "MoveSML: wrong entry type" );
|
|
952 |
User::Leave( KErrArgument );
|
|
953 |
}
|
|
954 |
|
|
955 |
// Find parent id, we'll be moving it's childs
|
|
956 |
TMsvId parentId = entryT.Parent();
|
|
957 |
|
|
958 |
// Make sure that the parent has changed
|
|
959 |
if (parentId != aParentId)
|
|
960 |
{
|
|
961 |
// Set parent as context
|
|
962 |
clientEntry->SetEntryL( parentId );
|
|
963 |
|
|
964 |
// Move the child item to another branch, use temporary waiter object
|
|
965 |
CMsvOperationActiveSchedulerWait* w = CMsvOperationActiveSchedulerWait::NewLC();
|
|
966 |
CMsvOperation* op = clientEntry->MoveL( aSmId, aParentId, w->iStatus );
|
|
967 |
w->Start();
|
|
968 |
SAFEDELETE( op );
|
|
969 |
CleanupStack::PopAndDestroy();
|
|
970 |
|
|
971 |
}
|
|
972 |
else
|
|
973 |
{
|
|
974 |
LOGGER_WRITE( "CSmsAdapterMsvApi::MoveSML, identical parents." );
|
|
975 |
}
|
|
976 |
|
|
977 |
CleanupStack::PopAndDestroy(); // entry
|
|
978 |
|
|
979 |
LOGGER_LEAVEFN( "CSmsAdapterMsvApi::MoveSML" );
|
|
980 |
}
|
|
981 |
|
|
982 |
// -----------------------------------------------------------------------------
|
|
983 |
// CSmsAdapterMsvApi::AddUserFolderL
|
|
984 |
// Creates new user folder
|
|
985 |
// -----------------------------------------------------------------------------
|
|
986 |
TInt CSmsAdapterMsvApi::AddUserFolderL( TMsvId& aFolder, const TDesC& aName )
|
|
987 |
{
|
|
988 |
LOGGER_ENTERFN( "CSmsAdapterMsvApi::AddUserFolderL" );
|
|
989 |
LOG(aName);
|
|
990 |
|
|
991 |
// Make sure that we are not going to add same folder twise
|
|
992 |
TBool found(EFalse);
|
|
993 |
found = FindUserFolderL(aName, aFolder);
|
|
994 |
if ( found )
|
|
995 |
{
|
|
996 |
LOGGER_WRITE( "Folder already exists" );
|
|
997 |
return KErrNone;
|
|
998 |
}
|
|
999 |
|
|
1000 |
CMsvEntry* entry = iSession->GetEntryL(KMsvMyFoldersEntryIdValue);
|
|
1001 |
CleanupStack::PushL( entry );
|
|
1002 |
|
|
1003 |
TTime date;
|
|
1004 |
date.UniversalTime();
|
|
1005 |
|
|
1006 |
TMsvEntry folderEntry;
|
|
1007 |
folderEntry.iType = KUidMsvFolderEntry;
|
|
1008 |
folderEntry.iMtm = KUidMsvLocalServiceMtm;
|
|
1009 |
folderEntry.iDetails.Set(aName);
|
|
1010 |
folderEntry.iServiceId = KMsvLocalServiceIndexEntryIdValue;
|
|
1011 |
folderEntry.iSize = sizeof(folderEntry);
|
|
1012 |
folderEntry.iDate = date;
|
|
1013 |
folderEntry.SetStandardFolder(EFalse);
|
|
1014 |
folderEntry.SetVisible(ETrue);
|
|
1015 |
folderEntry.SetComplete(ETrue);
|
|
1016 |
folderEntry.SetInPreparation(EFalse);
|
|
1017 |
folderEntry.SetReadOnly(EFalse);
|
|
1018 |
|
|
1019 |
entry->CreateL(folderEntry);
|
|
1020 |
CleanupStack::PopAndDestroy(entry);
|
|
1021 |
|
|
1022 |
aFolder = folderEntry.Id();
|
|
1023 |
LOGGER_LEAVEFN( "CSmsAdapterMsvApi::AddUserFolderL" );
|
|
1024 |
return KErrNone;
|
|
1025 |
}
|
|
1026 |
|
|
1027 |
// -----------------------------------------------------------------------------
|
|
1028 |
// CSmsAdapterMsvApi::UpdateUserFolderL
|
|
1029 |
// Updates user folder (changes name)
|
|
1030 |
// -----------------------------------------------------------------------------
|
|
1031 |
TInt CSmsAdapterMsvApi::UpdateUserFolderL( TMsvId aFolder, const TDesC& aName )
|
|
1032 |
{
|
|
1033 |
LOGGER_ENTERFN( "CSmsAdapterMsvApi::UpdateUserFolderL" );
|
|
1034 |
LOG(aName);
|
|
1035 |
|
|
1036 |
CMsvEntry* entry = iSession->GetEntryL( aFolder );
|
|
1037 |
CleanupStack::PushL( entry );
|
|
1038 |
|
|
1039 |
TMsvEntry tEntry = entry->Entry();
|
|
1040 |
|
|
1041 |
if ( tEntry.iType != KUidMsvFolderEntry )
|
|
1042 |
{
|
|
1043 |
CleanupStack::PopAndDestroy( entry );
|
|
1044 |
LOGGER_WRITE( "No message folder" );
|
|
1045 |
return KErrGeneral;
|
|
1046 |
}
|
|
1047 |
|
|
1048 |
tEntry.iDetails.Set(aName);
|
|
1049 |
tEntry.iDescription.Set(aName);
|
|
1050 |
|
|
1051 |
entry->ChangeL(tEntry);
|
|
1052 |
|
|
1053 |
CleanupStack::PopAndDestroy( entry );
|
|
1054 |
LOGGER_LEAVEFN( "CSmsAdapterMsvApi::UpdateUserFolderL" );
|
|
1055 |
return KErrNone;
|
|
1056 |
}
|
|
1057 |
|
|
1058 |
// -----------------------------------------------------------------------------
|
|
1059 |
// CSmsAdapterMsvApi::UniversalTimeFromHomeTime
|
|
1060 |
// Converts local time to universal time.
|
|
1061 |
// -----------------------------------------------------------------------------
|
|
1062 |
TTime CSmsAdapterMsvApi::UniversalTimeFromHomeTime( TTime aTime )
|
|
1063 |
{
|
|
1064 |
TLocale locale;
|
|
1065 |
locale.Refresh();
|
|
1066 |
|
|
1067 |
TTimeIntervalSeconds universalTimeOffset = locale.UniversalTimeOffset();
|
|
1068 |
aTime -= universalTimeOffset;
|
|
1069 |
|
|
1070 |
if (locale.QueryHomeHasDaylightSavingOn())
|
|
1071 |
{
|
|
1072 |
TTimeIntervalHours daylightSaving( 1 );
|
|
1073 |
aTime -= daylightSaving;
|
|
1074 |
}
|
|
1075 |
|
|
1076 |
return aTime;
|
|
1077 |
}
|
|
1078 |
|
|
1079 |
// -----------------------------------------------------------------------------
|
|
1080 |
// CSmsAdapterMsvApi::HomeTimeFromUniversalTime
|
|
1081 |
// Converts universal time to local time.
|
|
1082 |
// -----------------------------------------------------------------------------
|
|
1083 |
TTime CSmsAdapterMsvApi::HomeTimeFromUniversalTime( TTime aTime )
|
|
1084 |
{
|
|
1085 |
TLocale locale;
|
|
1086 |
locale.Refresh();
|
|
1087 |
|
|
1088 |
TTimeIntervalSeconds universalTimeOffset = locale.UniversalTimeOffset();
|
|
1089 |
aTime += universalTimeOffset;
|
|
1090 |
|
|
1091 |
if (locale.QueryHomeHasDaylightSavingOn())
|
|
1092 |
{
|
|
1093 |
TTimeIntervalHours daylightSaving( 1 );
|
|
1094 |
aTime += daylightSaving;
|
|
1095 |
}
|
|
1096 |
|
|
1097 |
return aTime;
|
|
1098 |
}
|
|
1099 |
|
|
1100 |
// -----------------------------------------------------------------------------
|
|
1101 |
// CSmsAdapterMsvApi::FetchNameFromContactsL
|
|
1102 |
// Searches contact name of given number from phone book
|
|
1103 |
// If not found, empty descriptor is returned.
|
|
1104 |
// -----------------------------------------------------------------------------
|
|
1105 |
void CSmsAdapterMsvApi::FetchNameFromContactsL(const TDesC& aNumber, TDes& aName)
|
|
1106 |
{
|
|
1107 |
LOGGER_ENTERFN( "CSmsAdapterMsvApi::FetchNameFromContactsL" );
|
|
1108 |
LOG(aNumber);
|
|
1109 |
|
|
1110 |
aName.Zero();
|
|
1111 |
|
|
1112 |
const TInt KNumDigitsToMatch(8);
|
|
1113 |
CContactIdArray* contactIds = iContactsDb->MatchPhoneNumberL(aNumber, KNumDigitsToMatch);
|
|
1114 |
if (contactIds->Count() != 1)
|
|
1115 |
{
|
|
1116 |
delete contactIds;
|
|
1117 |
return;
|
|
1118 |
}
|
|
1119 |
CleanupStack::PushL(contactIds);
|
|
1120 |
|
|
1121 |
CContactItem* item = iContactsDb->ReadContactLC((*contactIds)[0]);
|
|
1122 |
CContactItemFieldSet& fieldSet = item->CardFields();
|
64
|
1123 |
|
|
1124 |
TFileName database;
|
|
1125 |
iContactsDb->GetCurrentDatabase(database);
|
|
1126 |
|
40
|
1127 |
TPtrC familyName;
|
|
1128 |
TPtrC givenName;
|
|
1129 |
TInt pos;
|
|
1130 |
|
|
1131 |
pos = fieldSet.Find(KUidContactFieldFamilyName);
|
|
1132 |
if (pos >= 0)
|
|
1133 |
{
|
|
1134 |
CContactItemField& itemField=fieldSet[pos];
|
|
1135 |
if (!(itemField.IsHidden()) && !(itemField.IsDisabled()))
|
|
1136 |
{
|
|
1137 |
CContactTextField* textField = itemField.TextStorage();
|
|
1138 |
familyName.Set(textField->Text());
|
|
1139 |
}
|
|
1140 |
}
|
|
1141 |
pos = fieldSet.Find(KUidContactFieldGivenName);
|
|
1142 |
if (pos >= 0)
|
|
1143 |
{
|
|
1144 |
CContactItemField& itemField=fieldSet[pos];
|
|
1145 |
if (!(itemField.IsHidden()) && !(itemField.IsDisabled()))
|
|
1146 |
{
|
|
1147 |
CContactTextField* textField = itemField.TextStorage();
|
|
1148 |
givenName.Set(textField->Text());
|
|
1149 |
}
|
|
1150 |
}
|
|
1151 |
|
|
1152 |
TInt spaceLeft = aName.MaxLength();
|
|
1153 |
|
|
1154 |
if (familyName.Length() <= spaceLeft)
|
|
1155 |
{
|
|
1156 |
aName.Append(familyName);
|
|
1157 |
aName.Trim();
|
|
1158 |
spaceLeft -= aName.Length();
|
|
1159 |
}
|
|
1160 |
|
|
1161 |
if ((givenName.Length() + 1) <= spaceLeft)
|
|
1162 |
{
|
|
1163 |
aName.Append(' ');
|
|
1164 |
aName.Append(givenName);
|
|
1165 |
aName.Trim();
|
|
1166 |
}
|
|
1167 |
|
|
1168 |
LOG(aName);
|
|
1169 |
|
|
1170 |
CleanupStack::PopAndDestroy(2); // item, contactIds
|
|
1171 |
LOGGER_LEAVEFN( "CSmsAdapterMsvApi::FetchNameFromContactsL" );
|
|
1172 |
}
|
|
1173 |
|
|
1174 |
// End of file
|