|
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // SMS settings Parser |
|
15 // |
|
16 // |
|
17 |
|
18 #include <msvids.h> // KMsvRootIndexEntryId |
|
19 #include <msvuids.h> |
|
20 #include <msventry.h> |
|
21 #include <msvruids.h> |
|
22 // |
|
23 #include "BSP.H" |
|
24 #include "IACP.H" |
|
25 #include "SMSP.H" |
|
26 #include "IACPDEF.H" |
|
27 #include "IACPERR.H" |
|
28 #include <csmsaccount.h> |
|
29 |
|
30 #include "IMPMACRO.H" |
|
31 |
|
32 |
|
33 //-------------------------------------- |
|
34 // |
|
35 // Constructor |
|
36 // |
|
37 CSmsParser::CSmsParser() |
|
38 { |
|
39 } |
|
40 |
|
41 // |
|
42 // Factory fns |
|
43 // |
|
44 CSmsParser* CSmsParser::NewLC() |
|
45 { |
|
46 CSmsParser* self=new (ELeave) CSmsParser(); |
|
47 CleanupStack::PushL(self); |
|
48 self->ConstructL(); |
|
49 return self; |
|
50 } |
|
51 |
|
52 CSmsParser* CSmsParser::NewL() |
|
53 { |
|
54 CSmsParser* self=CSmsParser::NewLC(); |
|
55 CleanupStack::Pop(); |
|
56 return self; |
|
57 } |
|
58 |
|
59 // |
|
60 // 2nd stage of construction |
|
61 // |
|
62 void CSmsParser::ConstructL() |
|
63 { |
|
64 // --- Create the blank settings objects --- |
|
65 iSmsSettings= CSmsSettings::NewL(); |
|
66 } |
|
67 |
|
68 // |
|
69 // Destruction |
|
70 // |
|
71 CSmsParser::~CSmsParser() |
|
72 { |
|
73 delete iSmsSettings; |
|
74 delete iServiceCentreName; |
|
75 delete iServiceCentreAddress; |
|
76 } |
|
77 |
|
78 // |
|
79 // Parse/Set data members of CSmsSettings |
|
80 // |
|
81 void CSmsParser::ParseL(CParsedFieldCollection& aIacpFields) |
|
82 { |
|
83 TPtrC fieldValueBuf; |
|
84 |
|
85 // service center name |
|
86 if (aIacpFields.GetFieldValueAndLength(SMS_SERVICE_CENTER_NAME, fieldValueBuf) != 0) |
|
87 { |
|
88 delete iServiceCentreName; |
|
89 iServiceCentreName = NULL; |
|
90 iServiceCentreName=fieldValueBuf.AllocL(); |
|
91 } |
|
92 |
|
93 // service name |
|
94 if (aIacpFields.GetFieldValueAndLength(SMS_SERVICE_CENTER_ADDRESS, fieldValueBuf) != 0) |
|
95 { |
|
96 delete iServiceCentreAddress; |
|
97 iServiceCentreAddress = NULL; |
|
98 iServiceCentreAddress=fieldValueBuf.AllocL(); |
|
99 } |
|
100 |
|
101 if(iServiceCentreName == 0 || iServiceCentreAddress == 0 || |
|
102 !((*iServiceCentreName).Length()>0 && (*iServiceCentreAddress).Length() >0)) |
|
103 User::Leave(KIacpMandatoryDataNotSet); |
|
104 } |
|
105 // |
|
106 // Create sms service |
|
107 // |
|
108 void CSmsParser::ProcessL(CMSVENTRY& aEntry) |
|
109 { |
|
110 TMsvId entryId = aEntry.Entry().Id(); |
|
111 CSmsAccount* smsAccount = CSmsAccount::NewLC(); |
|
112 TRAPD(error, smsAccount->LoadSettingsL(*iSmsSettings)); |
|
113 if (error == KErrNone) |
|
114 { |
|
115 // update or create service centre address |
|
116 FindServiceCentreAddressL(); |
|
117 } |
|
118 else if (error == KErrNotFound) |
|
119 { |
|
120 // settings not found, create new |
|
121 smsAccount->InitialiseDefaultSettingsL(*iSmsSettings); |
|
122 iSmsSettings->AddServiceCenterL(*iServiceCentreName, *iServiceCentreAddress); |
|
123 } |
|
124 else |
|
125 { |
|
126 User::Leave(error); |
|
127 } |
|
128 smsAccount->SaveSettingsL(*iSmsSettings); |
|
129 CleanupStack::PopAndDestroy(smsAccount); |
|
130 // go back to msg's context |
|
131 SETENTRYL(entryId); |
|
132 } |
|
133 |
|
134 |
|
135 |
|
136 void CSmsParser::FindServiceCentreAddressL() |
|
137 { |
|
138 TBool foundAddress = EFalse; |
|
139 TInt numSCentres = iSmsSettings->ServiceCenterCount(); |
|
140 TInt currentSC = 0; |
|
141 while(currentSC < numSCentres && !foundAddress) |
|
142 { |
|
143 CSmsServiceCenter& number = iSmsSettings->GetServiceCenter(currentSC); |
|
144 // compare name if there update else look at next SC |
|
145 if(number.Name().CompareC(*iServiceCentreName)==0) |
|
146 { |
|
147 number.SetAddressL(*iServiceCentreAddress); |
|
148 foundAddress = ETrue; |
|
149 } |
|
150 else |
|
151 currentSC++; |
|
152 } |
|
153 if(!foundAddress) |
|
154 { |
|
155 iSmsSettings->AddServiceCenterL(*iServiceCentreName,*iServiceCentreAddress); |
|
156 iSmsSettings->SetDefaultServiceCenter(numSCentres); |
|
157 } |
|
158 } |