1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 #include <msvuids.h> |
|
18 #include <msvids.h> |
|
19 #include <msvschedulesettings.h> |
|
20 #include <msvoffpeaktime.h> |
|
21 #include <msvsenderroraction.h> |
|
22 #include <msvsysagentaction.h> |
|
23 #include <centralrepository.h> |
|
24 #include <tmsvschedulesettingsutils.h> |
|
25 |
|
26 #include "SMUTSET.H" |
|
27 #include <csmsaccount.h> |
|
28 #include <smut.h> |
|
29 |
|
30 #if (defined SYMBIAN_MESSAGESTORE_HEADER_BODY_USING_SQLDB) |
|
31 #include <msvapi.h> |
|
32 #endif |
|
33 |
|
34 const TUint32 KIncrementSC = 0x00000010; |
|
35 const TInt KMaxSettingLength = 256; |
|
36 const TInt KMaxServiceCenterId = 256; |
|
37 const TInt KSmsSettingsVersion = 1; |
|
38 const TInt KSmsMessageSettingsVersion = 1; |
|
39 |
|
40 |
|
41 /** |
|
42 Allocates and constructs an SMS account object. |
|
43 |
|
44 Initialises all member data to their default values. |
|
45 |
|
46 @return |
|
47 The newly constructed SMS account object. |
|
48 */ |
|
49 EXPORT_C CSmsAccount* CSmsAccount::NewL() |
|
50 { |
|
51 CSmsAccount* self = CSmsAccount::NewLC(); |
|
52 CleanupStack::Pop(self); |
|
53 return self; |
|
54 } |
|
55 |
|
56 /** |
|
57 Allocates and constructs an SMS account object. |
|
58 |
|
59 Initialises all member data to their default values. |
|
60 |
|
61 @return |
|
62 The newly constructed SMS account object. |
|
63 */ |
|
64 EXPORT_C CSmsAccount* CSmsAccount::NewLC() |
|
65 { |
|
66 CSmsAccount* self = new (ELeave) CSmsAccount(); |
|
67 CleanupStack::PushL(self); |
|
68 self->ConstructL(); |
|
69 return self; |
|
70 } |
|
71 |
|
72 /** |
|
73 Second phase construction. |
|
74 */ |
|
75 void CSmsAccount::ConstructL() |
|
76 { |
|
77 iRepository = CRepository::NewL(KUidMsgTypeSMS); |
|
78 } |
|
79 |
|
80 /** |
|
81 Constructor. |
|
82 */ |
|
83 CSmsAccount::CSmsAccount() |
|
84 { |
|
85 } |
|
86 |
|
87 /** |
|
88 Destructor. |
|
89 */ |
|
90 EXPORT_C CSmsAccount::~CSmsAccount() |
|
91 { |
|
92 delete iRepository; |
|
93 delete iMsvSession; |
|
94 } |
|
95 |
|
96 /** |
|
97 Initialises the SMS settings in CenRep: |
|
98 |
|
99 1. Creates a SMS service entry in the message store |
|
100 |
|
101 2. Resets the settings in CenRep to their default values |
|
102 |
|
103 3. Populates aSmsSettings with default settings |
|
104 |
|
105 @param aSmsSettings |
|
106 SMS service settings |
|
107 */ |
|
108 EXPORT_C void CSmsAccount::InitialiseDefaultSettingsL(CSmsSettings& aSmsSettings) |
|
109 { |
|
110 ResetSettings(); |
|
111 CreateSmsServiceL(); |
|
112 LoadSettingsL(aSmsSettings); |
|
113 } |
|
114 |
|
115 /** |
|
116 Initialises the SMS settings in CenRep: |
|
117 |
|
118 1. Creates a SMS service entry in the message store |
|
119 |
|
120 2. Resets the settings in CenRep to their default values |
|
121 |
|
122 3. Populates the supplied objects with default settings |
|
123 |
|
124 @param aScheduleSettings |
|
125 Schedule settings |
|
126 |
|
127 @param aOffPeakTimes |
|
128 Off Peak Times |
|
129 |
|
130 @param aErrorActions |
|
131 Send Error Actions |
|
132 |
|
133 @param aSysAgentActions |
|
134 System Agent Actions |
|
135 */ |
|
136 EXPORT_C void CSmsAccount::InitialiseDefaultSettingsL(CMsvScheduleSettings& aScheduleSettings, CMsvOffPeakTimes& aOffPeakTimes, CMsvSendErrorActions& aErrorActions, CMsvSysAgentActions& aSysAgentActions) |
|
137 { |
|
138 ResetSettings(); |
|
139 CreateSmsServiceL(); |
|
140 LoadSettingsL(aScheduleSettings, aOffPeakTimes, aErrorActions, aSysAgentActions); |
|
141 } |
|
142 |
|
143 /** |
|
144 Creates SMS service entry in the message store |
|
145 */ |
|
146 TMsvId CSmsAccount::CreateSmsServiceL() |
|
147 { |
|
148 #if (defined SYMBIAN_MESSAGESTORE_HEADER_BODY_USING_SQLDB) |
|
149 CreateHeaderStoreL(); |
|
150 #endif |
|
151 |
|
152 TMsvId serviceEntryId = KMsvNullIndexEntryId; |
|
153 CMsvEntry* root = SessionL().GetEntryL(KMsvRootIndexEntryId); |
|
154 CleanupStack::PushL(root); |
|
155 |
|
156 TRAPD(error, TSmsUtilities::ServiceIdL(*root, serviceEntryId)); |
|
157 if (error == KErrNotFound) |
|
158 { |
|
159 TBuf<KMaxSettingLength> accountName; |
|
160 User::LeaveIfError(iRepository->Get(ESmsAccountNameId, accountName)); |
|
161 |
|
162 TMsvEntry entry; |
|
163 entry.iMtm = KUidMsgTypeSMS; |
|
164 entry.iType = KUidMsvServiceEntry; |
|
165 entry.SetReadOnly(EFalse); |
|
166 entry.SetVisible(EFalse); |
|
167 entry.iDate.UniversalTime(); |
|
168 entry.iDetails.Set(accountName); |
|
169 root->SetEntryL(KMsvRootIndexEntryId); |
|
170 root->CreateL(entry); |
|
171 serviceEntryId = entry.Id(); |
|
172 } |
|
173 else |
|
174 { |
|
175 User::LeaveIfError(error); |
|
176 } |
|
177 |
|
178 CleanupStack::PopAndDestroy(root); |
|
179 |
|
180 User::LeaveIfError(iRepository->Set(ESmsServiceId, static_cast<TInt>(serviceEntryId))); |
|
181 return serviceEntryId; |
|
182 } |
|
183 |
|
184 /** |
|
185 Resets the settings in CenRep to their default values. |
|
186 */ |
|
187 void CSmsAccount::ResetSettings() |
|
188 { |
|
189 iRepository->Reset(); |
|
190 } |
|
191 |
|
192 /** |
|
193 Loads SMS Service settings from CenRep: |
|
194 |
|
195 @param aSmsSettings |
|
196 Sms service settings |
|
197 */ |
|
198 EXPORT_C void CSmsAccount::LoadSettingsL(CSmsSettings& aSmsSettings) |
|
199 { |
|
200 TInt temp = 0; |
|
201 |
|
202 //Load SMS Message Settings |
|
203 User::LeaveIfError(iRepository->Get(ESmsValidityPeriodId, temp)); |
|
204 aSmsSettings.SetValidityPeriod(TTimeIntervalMinutes(temp)); |
|
205 |
|
206 User::LeaveIfError(iRepository->Get(ESmsValidityPeriodFormatId, temp)); |
|
207 aSmsSettings.SetValidityPeriodFormat(static_cast<TSmsFirstOctet::TSmsValidityPeriodFormat>(temp)); |
|
208 |
|
209 User::LeaveIfError(iRepository->Get(ESmsAlphabetId, temp)); |
|
210 aSmsSettings.SetCharacterSet(static_cast<TSmsDataCodingScheme::TSmsAlphabet>(temp)); |
|
211 |
|
212 User::LeaveIfError(iRepository->Get(ESmsMsgFlagsId, temp)); |
|
213 aSmsSettings.SetMessageFlags(static_cast<TUint32>(temp)); |
|
214 |
|
215 User::LeaveIfError(iRepository->Get(ESmsMessageConversionId, temp)); |
|
216 aSmsSettings.SetMessageConversion(static_cast<TSmsPIDConversion>(temp)); |
|
217 |
|
218 |
|
219 // Load SMS Service Settings |
|
220 User::LeaveIfError(iRepository->Get(ESmsFlagsId, temp)); |
|
221 aSmsSettings.SetSettingsFlags(static_cast<TUint32>(temp)); |
|
222 |
|
223 User::LeaveIfError(iRepository->Get(ESmsStatusReportHandlingId, temp)); |
|
224 aSmsSettings.SetStatusReportHandling(static_cast<CSmsSettings::TSmsReportHandling>(temp)); |
|
225 |
|
226 User::LeaveIfError(iRepository->Get(ESmsSpecialMessageHandlingId, temp)); |
|
227 aSmsSettings.SetSpecialMessageHandling(static_cast<CSmsSettings::TSmsReportHandling>(temp)); |
|
228 |
|
229 User::LeaveIfError(iRepository->Get(ESmsCommDbActionId, temp)); |
|
230 aSmsSettings.SetCommDbAction(static_cast<CSmsSettings::TSmsSettingsCommDbAction>(temp)); |
|
231 |
|
232 User::LeaveIfError(iRepository->Get(ESmsDeliveryId, temp)); |
|
233 aSmsSettings.SetDelivery(static_cast<TSmsDelivery>(temp)); |
|
234 |
|
235 aSmsSettings.RemoveSCAddresses(); |
|
236 User::LeaveIfError(iRepository->Get(ESmsSCAddressesCountId, temp)); |
|
237 TInt count = temp; |
|
238 |
|
239 TUint32 scId = ESmsSCAddressesPartialId; // 0x1000 |
|
240 TUint32 scFieldId = 0; |
|
241 TBuf<KMaxSettingLength> scNumber; |
|
242 TBuf<KMaxSettingLength> scName; |
|
243 while(count--) |
|
244 { |
|
245 scFieldId = scId; // 0x0 - address field |
|
246 User::LeaveIfError(iRepository->Get(scFieldId, scNumber)); |
|
247 |
|
248 ++scFieldId; // 0x1 - name field, increment the last bit |
|
249 User::LeaveIfError(iRepository->Get(scFieldId, scName)); |
|
250 |
|
251 aSmsSettings.AddServiceCenterL(scName, scNumber); |
|
252 scId += KIncrementSC; // get the next SC in the list |
|
253 } |
|
254 |
|
255 if (aSmsSettings.ServiceCenterCount()>0) |
|
256 { |
|
257 User::LeaveIfError(iRepository->Get(ESmsDefaultSCId, temp)); |
|
258 aSmsSettings.SetDefaultServiceCenter(temp); |
|
259 } |
|
260 |
|
261 User::LeaveIfError(iRepository->Get(ESmsBearerActionId, temp)); |
|
262 aSmsSettings.SetSmsBearerAction(static_cast<CSmsSettings::TSmsSettingsCommDbAction>(temp)); |
|
263 |
|
264 User::LeaveIfError(iRepository->Get(ESmsBearerId, temp)); |
|
265 aSmsSettings.SetSmsBearer(static_cast<CSmsSettings::TMobileSmsBearer>(temp)); |
|
266 |
|
267 User::LeaveIfError(iRepository->Get(ESmsClass2FolderId, temp)); |
|
268 aSmsSettings.SetClass2Folder(static_cast<TMsvId>(temp)); |
|
269 |
|
270 User::LeaveIfError(iRepository->Get(ESmsDescriptionLengthId, temp)); |
|
271 aSmsSettings.SetDescriptionLength(temp); |
|
272 TInt err = iRepository->Get(EMsgSMSTimeStampSettings, temp); |
|
273 if(KErrNone == err ) |
|
274 { |
|
275 aSmsSettings.SetUseServiceCenterTimeStampForDate(temp); |
|
276 } |
|
277 } |
|
278 |
|
279 /** |
|
280 Loads Schedule Send settings from CenRep: |
|
281 |
|
282 @param aScheduleSettings |
|
283 Schedule settings |
|
284 |
|
285 @param aOffPeakTimes |
|
286 Off Peak Times |
|
287 |
|
288 @param aErrorActions |
|
289 Send Error Actions |
|
290 |
|
291 @param aSysAgentActions |
|
292 System Agent Actions |
|
293 */ |
|
294 EXPORT_C void CSmsAccount::LoadSettingsL(CMsvScheduleSettings& aScheduleSettings, CMsvOffPeakTimes& aOffPeakTimes, CMsvSendErrorActions& aErrorActions, CMsvSysAgentActions& aSysAgentActions) |
|
295 { |
|
296 |
|
297 TMsvScheduleSettingsUtils::LoadScheduleSettingsL(aScheduleSettings, *iRepository); |
|
298 TMsvScheduleSettingsUtils::LoadOffPeakSettingsL(aOffPeakTimes, *iRepository); |
|
299 TMsvScheduleSettingsUtils::LoadSendErrorSettingsL(aErrorActions, *iRepository); |
|
300 TMsvScheduleSettingsUtils::LoadSysAgentSettingsL(aSysAgentActions, *iRepository); |
|
301 } |
|
302 |
|
303 /** |
|
304 Saves SMS Service settings to CenRep: |
|
305 |
|
306 @param aSmsSettings |
|
307 Sms service settings |
|
308 */ |
|
309 EXPORT_C void CSmsAccount::SaveSettingsL(const CSmsSettings& aSmsSettings) const |
|
310 { |
|
311 |
|
312 User::LeaveIfError(iRepository->StartTransaction(CRepository::EReadWriteTransaction)); |
|
313 iRepository->CleanupRollbackTransactionPushL(); |
|
314 iRepository->Set(ESmsSettingsVersionId, KSmsSettingsVersion); // Errors are ignored as the CenRep transaction fails on error. |
|
315 |
|
316 // Save SMS Message Settings¬ |
|
317 iRepository->Set(ESmsSettingsMesssageVersionId, KSmsMessageSettingsVersion); |
|
318 iRepository->Set(ESmsValidityPeriodId, aSmsSettings.ValidityPeriod().Int()); |
|
319 iRepository->Set(ESmsValidityPeriodFormatId, static_cast<TInt>(aSmsSettings.ValidityPeriodFormat())); |
|
320 iRepository->Set(ESmsAlphabetId, static_cast<TInt>(aSmsSettings.CharacterSet())); |
|
321 iRepository->Set(ESmsMsgFlagsId, static_cast<TInt>(aSmsSettings.MessageFlags())); |
|
322 iRepository->Set(ESmsMessageConversionId, static_cast<TInt>(aSmsSettings.MessageConversion())); |
|
323 |
|
324 |
|
325 // Save SMS Service Settings |
|
326 iRepository->Set(ESmsFlagsId, static_cast<TInt>(aSmsSettings.SettingsFlags())); |
|
327 iRepository->Set(ESmsStatusReportHandlingId, static_cast<TInt>(aSmsSettings.StatusReportHandling())); |
|
328 iRepository->Set(ESmsSpecialMessageHandlingId, static_cast<TInt>(aSmsSettings.SpecialMessageHandling())); |
|
329 iRepository->Set(ESmsCommDbActionId, static_cast<TInt>(aSmsSettings.CommDbAction())); |
|
330 iRepository->Set(ESmsDeliveryId, static_cast<TInt>(aSmsSettings.Delivery())); |
|
331 iRepository->Set(ESmsDefaultSCId, aSmsSettings.DefaultServiceCenter()); |
|
332 |
|
333 TInt count = aSmsSettings.ServiceCenterCount(); |
|
334 __ASSERT_ALWAYS(count<=KMaxServiceCenterId, User::Leave(KErrOverflow)); |
|
335 iRepository->Set(ESmsSCAddressesCountId, count); |
|
336 |
|
337 // Save list of SC |
|
338 TUint32 scId = ESmsSCAddressesPartialId; // 0x1000 |
|
339 TUint32 scFieldId = 0; |
|
340 for(TInt loop=0; loop < count; ++loop) |
|
341 { |
|
342 scFieldId = scId; // 0x0 - address field |
|
343 iRepository->Set(scFieldId, aSmsSettings.GetServiceCenter(loop).Address()); |
|
344 |
|
345 ++scFieldId; // 0x1 - name field, increment the last bit |
|
346 iRepository->Set(scFieldId, aSmsSettings.GetServiceCenter(loop).Name()); |
|
347 |
|
348 scId += KIncrementSC; // get the next SC in the list |
|
349 } |
|
350 |
|
351 iRepository->Set(ESmsBearerActionId, static_cast<TInt>(aSmsSettings.SmsBearerAction())); |
|
352 iRepository->Set(ESmsBearerId, static_cast<TInt>(aSmsSettings.SmsBearer())); |
|
353 iRepository->Set(ESmsClass2FolderId, static_cast<TInt>(aSmsSettings.Class2Folder())); |
|
354 iRepository->Set(ESmsDescriptionLengthId, aSmsSettings.DescriptionLength()); |
|
355 |
|
356 TInt temp = 0; |
|
357 TInt err = iRepository->Get(EMsgSMSTimeStampSettings, temp); |
|
358 if(KErrNone == err ) |
|
359 { |
|
360 temp = (aSmsSettings.UseServiceCenterTimeStampForDate()) ? 1: 0; |
|
361 iRepository->Set(EMsgSMSTimeStampSettings,temp); |
|
362 } |
|
363 CleanupStack::Pop(); |
|
364 TUint32 errorId = 0; |
|
365 User::LeaveIfError(iRepository->CommitTransaction(errorId)); |
|
366 |
|
367 aSmsSettings.StoreToCommDbL(); |
|
368 } |
|
369 |
|
370 /** |
|
371 Saves Schedule Send settings to CenRep: |
|
372 |
|
373 @param aScheduleSettings |
|
374 Schedule settings |
|
375 |
|
376 @param aOffPeakTimes |
|
377 Off Peak Times |
|
378 |
|
379 @param aErrorActions |
|
380 Send Error Actions |
|
381 |
|
382 @param aSysAgentActions |
|
383 System Agent Actions |
|
384 */ |
|
385 EXPORT_C void CSmsAccount::SaveSettingsL(const CMsvScheduleSettings& aScheduleSettings, const CMsvOffPeakTimes& aOffPeakTimes, const CMsvSendErrorActions& aErrorActions, const CMsvSysAgentActions& aSysAgentActions) const |
|
386 { |
|
387 |
|
388 User::LeaveIfError(iRepository->StartTransaction(CRepository::EReadWriteTransaction)); |
|
389 iRepository->CleanupRollbackTransactionPushL(); |
|
390 |
|
391 TMsvScheduleSettingsUtils::SaveScheduleSettingsL(aScheduleSettings, *iRepository); |
|
392 TMsvScheduleSettingsUtils::SaveOffPeakSettingsL(aOffPeakTimes, *iRepository); |
|
393 TMsvScheduleSettingsUtils::SaveSendErrorSettingsL(aErrorActions, *iRepository); |
|
394 TMsvScheduleSettingsUtils::SaveSysAgentSettingsL(aSysAgentActions, *iRepository); |
|
395 |
|
396 CleanupStack::Pop(); |
|
397 TUint32 errorId = 0; |
|
398 User::LeaveIfError(iRepository->CommitTransaction(errorId)); |
|
399 } |
|
400 |
|
401 CMsvSession& CSmsAccount::SessionL() |
|
402 { |
|
403 if (iMsvSession == NULL) |
|
404 { |
|
405 iMsvSession = CMsvSession::OpenSyncL(*this); |
|
406 } |
|
407 |
|
408 return *iMsvSession; |
|
409 } |
|
410 |
|
411 void CSmsAccount::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* , TAny* , TAny* ) |
|
412 { |
|
413 if (aEvent == EMsvCloseSession) |
|
414 { |
|
415 delete iMsvSession; |
|
416 iMsvSession = NULL; |
|
417 } |
|
418 } |
|
419 |
|
420 |
|
421 #if (defined SYMBIAN_MESSAGESTORE_HEADER_BODY_USING_SQLDB) |
|
422 /** |
|
423 * Send the header structure to message Server to create header table. |
|
424 * @param None. |
|
425 * @return None. |
|
426 */ |
|
427 void CSmsAccount::CreateHeaderStoreL() |
|
428 { |
|
429 CMsvHeaderStore* aHeader = CMsvHeaderStore::NewL(KUidMsgTypeSMS ,SessionL()); |
|
430 CleanupStack::PushL(aHeader); |
|
431 |
|
432 _LIT (KSmsHeaderversion , "SmsHeadearversion"); |
|
433 aHeader->AddFieldL(KSmsHeaderversion().AllocL(),EIntegerField); |
|
434 |
|
435 _LIT (KSmsRecipientCount , "RecipientCount"); |
|
436 aHeader->AddFieldL(KSmsRecipientCount().AllocL(),EIntegerField); |
|
437 |
|
438 _LIT (KRecipients , "To"); |
|
439 aHeader->AddFieldL(KRecipients().AllocL(),ETextField); |
|
440 |
|
441 _LIT (KSmsFlags , "SmsFlags"); |
|
442 aHeader->AddFieldL(KSmsFlags().AllocL(),EIntegerField); |
|
443 |
|
444 _LIT (KTextBioMsgIdType,"BioMsgIdType"); |
|
445 aHeader->AddFieldL(KTextBioMsgIdType().AllocL(),EIntegerField); |
|
446 |
|
447 aHeader->CreateStoreL(); |
|
448 CleanupStack::PopAndDestroy(aHeader); //aHeader |
|
449 } |
|
450 #endif |
|