|
1 /* |
|
2 * Copyright (c) 2006 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 |
|
19 #include <s32strm.h> |
|
20 #include <badesca.h> |
|
21 |
|
22 #include "ncdqueryselectionitemimpl.h" |
|
23 #include "ncd_cp_queryelement.h" |
|
24 #include "ncdqueryoptionimpl.h" |
|
25 #include "catalogsinterfaceidentifier.h" |
|
26 #include "catalogsconstants.h" |
|
27 #include "catalogsdebug.h" |
|
28 #include "ncdqueryimpl.h" |
|
29 #include "ncdlocalizerutils.h" |
|
30 |
|
31 |
|
32 // ======== MEMBER FUNCTIONS ======== |
|
33 |
|
34 CNcdQuerySelectionItem* CNcdQuerySelectionItem::NewL( |
|
35 RReadStream& aReadStream, CNcdQuery& aParent ) |
|
36 { |
|
37 CNcdQuerySelectionItem* self = CNcdQuerySelectionItem::NewLC( aReadStream, aParent ); |
|
38 CleanupStack::Pop( self ); |
|
39 return self; |
|
40 } |
|
41 |
|
42 CNcdQuerySelectionItem* CNcdQuerySelectionItem::NewLC( |
|
43 RReadStream& aReadStream, CNcdQuery& aParent ) |
|
44 { |
|
45 CNcdQuerySelectionItem* self = new ( ELeave ) CNcdQuerySelectionItem( aParent ); |
|
46 // Using PushL because the object does not have any references yet |
|
47 CleanupStack::PushL( self ); |
|
48 |
|
49 self->ConstructL(); |
|
50 self->InternalizeL( aReadStream ); |
|
51 self->CreateSelectionTextsL(); |
|
52 return self; |
|
53 } |
|
54 |
|
55 CNcdQuerySelectionItem* CNcdQuerySelectionItem::NewL( |
|
56 const MNcdConfigurationProtocolQueryElement& aQueryElement, |
|
57 CNcdQuery& aParent ) |
|
58 { |
|
59 CNcdQuerySelectionItem* self = CNcdQuerySelectionItem::NewLC( aQueryElement, aParent ); |
|
60 CleanupStack::Pop( self ); |
|
61 return self; |
|
62 } |
|
63 |
|
64 CNcdQuerySelectionItem* CNcdQuerySelectionItem::NewLC( |
|
65 const MNcdConfigurationProtocolQueryElement& aQueryElement, |
|
66 CNcdQuery& aParent ) |
|
67 { |
|
68 CNcdQuerySelectionItem* self = new ( ELeave ) CNcdQuerySelectionItem( aParent ); |
|
69 // Using PushL because the object does not have any references yet |
|
70 CleanupStack::PushL( self ); |
|
71 |
|
72 self->ConstructL(); |
|
73 self->InternalizeL( aQueryElement ); |
|
74 self->CreateSelectionTextsL(); |
|
75 return self; |
|
76 } |
|
77 |
|
78 CNcdQuerySelectionItem* CNcdQuerySelectionItem::NewL( |
|
79 const RPointerArray<CNcdString>& aPaymentMethodNames, |
|
80 const MDesC8Array& aPaymentMethodTypes, |
|
81 CNcdQuery& aParent ) |
|
82 { |
|
83 CNcdQuerySelectionItem* self = |
|
84 CNcdQuerySelectionItem::NewLC( aPaymentMethodNames, aPaymentMethodTypes, aParent ); |
|
85 CleanupStack::Pop( self ); |
|
86 return self; |
|
87 } |
|
88 |
|
89 CNcdQuerySelectionItem* CNcdQuerySelectionItem::NewLC( |
|
90 const RPointerArray<CNcdString>& aPaymentMethodNames, |
|
91 const MDesC8Array& aPaymentMethodTypes, |
|
92 CNcdQuery& aParent ) |
|
93 { |
|
94 CNcdQuerySelectionItem* self = new ( ELeave ) CNcdQuerySelectionItem( aParent ); |
|
95 // Using PushL because the object does not have any references yet |
|
96 CleanupStack::PushL( self ); |
|
97 |
|
98 self->ConstructL( aPaymentMethodNames, aPaymentMethodTypes ); |
|
99 self->CreateSelectionTextsL(); |
|
100 return self; |
|
101 } |
|
102 |
|
103 void CNcdQuerySelectionItem::InternalizeL( RReadStream& aReadStream ) |
|
104 { |
|
105 CNcdQueryItem::InternalizeL( aReadStream ); |
|
106 iSelection = aReadStream.ReadInt32L(); |
|
107 TInt selectionCount = aReadStream.ReadInt32L(); |
|
108 |
|
109 for ( TInt i = 0 ; i < selectionCount ; i++ ) |
|
110 { |
|
111 CNcdQueryOption* option = CNcdQueryOption::NewLC( aReadStream ); |
|
112 iOptions.AppendL( option ); |
|
113 CleanupStack::Pop( option ); |
|
114 } |
|
115 |
|
116 delete iSelectionTexts; |
|
117 iSelectionTexts = NULL; |
|
118 |
|
119 delete iSelectionData; |
|
120 iSelectionData = NULL; |
|
121 iSelectionData = new (ELeave) CDesC8ArrayFlat( KListGranularity ); |
|
122 |
|
123 for ( TInt i = 0 ; i < iOptions.Count() ; i++ ) |
|
124 { |
|
125 iSelectionData->AppendL( iOptions[i]->Data() ); |
|
126 } |
|
127 } |
|
128 |
|
129 void CNcdQuerySelectionItem::InternalizeL( |
|
130 const MNcdConfigurationProtocolQueryElement& aQueryElement ) |
|
131 { |
|
132 CNcdQueryItem::InternalizeL( aQueryElement ); |
|
133 for ( TInt i = 0 ; i < aQueryElement.OptionCount() ; i++ ) |
|
134 { |
|
135 CNcdQueryOption* option = CNcdQueryOption::NewLC( |
|
136 aQueryElement.Option( i ) ); |
|
137 iOptions.AppendL( option ); |
|
138 CleanupStack::Pop( option ); |
|
139 } |
|
140 |
|
141 delete iSelectionTexts; |
|
142 iSelectionTexts = NULL; |
|
143 delete iSelectionData; |
|
144 iSelectionData = NULL; |
|
145 iSelectionData = new (ELeave) CDesC8ArrayFlat( KListGranularity ); |
|
146 |
|
147 for ( TInt i = 0 ; i < iOptions.Count() ; i++ ) |
|
148 { |
|
149 iSelectionData->AppendL( iOptions[i]->Data() ); |
|
150 } |
|
151 |
|
152 } |
|
153 |
|
154 void CNcdQuerySelectionItem::ExternalizeL( RWriteStream& aWriteStream ) const |
|
155 { |
|
156 CNcdQueryItem::ExternalizeL( aWriteStream ); |
|
157 aWriteStream.WriteInt32L( iSelection ); |
|
158 aWriteStream.WriteInt32L( iOptions.Count() ); |
|
159 for ( TInt i = 0 ; i < iOptions.Count() ; i++ ) |
|
160 { |
|
161 iOptions[i]->ExternalizeL( aWriteStream ); |
|
162 } |
|
163 } |
|
164 |
|
165 |
|
166 TInt CNcdQuerySelectionItem::Selection() const |
|
167 { |
|
168 return iSelection; |
|
169 } |
|
170 |
|
171 const MDesCArray& CNcdQuerySelectionItem::SelectionTexts() const |
|
172 { |
|
173 DLTRACEIN(("")); |
|
174 return *iSelectionTexts; |
|
175 } |
|
176 |
|
177 const MDesC8Array& CNcdQuerySelectionItem::SelectionData() const |
|
178 { |
|
179 return *iSelectionData; |
|
180 } |
|
181 |
|
182 void CNcdQuerySelectionItem::SetSelectionL( TInt aIndex ) |
|
183 { |
|
184 if ( aIndex < 0 || aIndex > iOptions.Count() ) |
|
185 { |
|
186 User::Leave( KErrArgument ); |
|
187 } |
|
188 iSelection = aIndex; |
|
189 iIsSet = ETrue; |
|
190 } |
|
191 |
|
192 TNcdInterfaceId CNcdQuerySelectionItem::Type() const |
|
193 { |
|
194 return static_cast<TNcdInterfaceId>(MNcdQuerySelectionItem::KInterfaceUid); |
|
195 } |
|
196 |
|
197 const TDesC& CNcdQuerySelectionItem::ValueL() |
|
198 { |
|
199 if ( iSelection < 0 || iSelection > iOptions.Count() || ! iIsSet ) |
|
200 { |
|
201 User::Leave( KErrArgument ); |
|
202 } |
|
203 return iOptions[iSelection]->Value(); |
|
204 } |
|
205 |
|
206 CNcdQuerySelectionItem::~CNcdQuerySelectionItem() |
|
207 { |
|
208 DLTRACEIN(("")); |
|
209 delete iSelectionTexts; |
|
210 delete iSelectionData; |
|
211 iOptions.ResetAndDestroy(); |
|
212 } |
|
213 |
|
214 CNcdQuerySelectionItem::CNcdQuerySelectionItem( CNcdQuery& aParent ) |
|
215 : CNcdQueryItem( aParent ) |
|
216 { |
|
217 } |
|
218 |
|
219 void CNcdQuerySelectionItem::ConstructL() |
|
220 { |
|
221 CNcdQueryItem::ConstructL(); |
|
222 // Register the interfaces of this object |
|
223 MNcdQuerySelectionItem* queryItem( this ); |
|
224 AddInterfaceL( |
|
225 CCatalogsInterfaceIdentifier::NewL( |
|
226 queryItem, this, MNcdQuerySelectionItem::KInterfaceUid ) ); |
|
227 } |
|
228 |
|
229 void CNcdQuerySelectionItem::ConstructL( const RPointerArray<CNcdString>& aPaymentMethodNames, |
|
230 const MDesC8Array& aPaymentMethodTypes ) |
|
231 { |
|
232 ConstructL(); |
|
233 |
|
234 DASSERT( aPaymentMethodNames.Count() == aPaymentMethodTypes.MdcaCount() ); |
|
235 |
|
236 TInt count = aPaymentMethodNames.Count(); |
|
237 CNcdQueryOption* option; |
|
238 for( TInt i = 0; i < count; i++ ) |
|
239 { |
|
240 option = CNcdQueryOption::NewLC( *aPaymentMethodNames[ i ], aPaymentMethodTypes.MdcaPoint( i ) ); |
|
241 iOptions.AppendL( option ); |
|
242 CleanupStack::Pop( option ); |
|
243 } |
|
244 } |
|
245 |
|
246 void CNcdQuerySelectionItem::CreateSelectionTextsL() |
|
247 { |
|
248 delete iSelectionTexts; |
|
249 iSelectionTexts = NULL; |
|
250 iSelectionTexts = new (ELeave) CDesC16ArrayFlat( KListGranularity ); |
|
251 // Use the string localizer to create selection texts. |
|
252 for ( TInt i = 0; i < iOptions.Count(); i++ ) |
|
253 { |
|
254 const CNcdString& string = iOptions[i]->Name(); |
|
255 HBufC* stringBuf( NULL ); |
|
256 // returns KNullDesC if localizer not available |
|
257 const TDesC& localizedString = CNcdLocalizerUtils::LocalizedString( |
|
258 string, iParentQuery.ClientLocalizer(), stringBuf ); |
|
259 if ( stringBuf ) |
|
260 { |
|
261 CleanupStack::PushL( stringBuf ); |
|
262 iSelectionTexts->AppendL( *stringBuf ); |
|
263 CleanupStack::PopAndDestroy( stringBuf ); |
|
264 } |
|
265 else |
|
266 { |
|
267 iSelectionTexts->AppendL( localizedString ); |
|
268 } |
|
269 } |
|
270 } |