1 /* |
|
2 * Copyright (c) 2002 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: Provisioning context list |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CWPCxContainer.h" |
|
21 #include <stringloader.h> |
|
22 #include <aknlists.h> |
|
23 #include <barsread.h> |
|
24 #include <provisioningcx.rsg> |
|
25 #include <csxhelp/prov.hlp.hrh> |
|
26 #include "CWPEngine.h" |
|
27 #include "ProvisioningUids.h" |
|
28 #include "ProvisioningCx.hrh" |
|
29 #include "Provisioningdebug.h" |
|
30 |
|
31 // CONSTANTS |
|
32 /// Granularity of the lines array |
|
33 const TInt KLinesGranularity = 3; |
|
34 /// Maximum number of characters in one line |
|
35 const TInt KMaxLineLength = 128; |
|
36 /// Number of tabs in front of the line |
|
37 const TInt KNumTabsPrepended = 1; |
|
38 /// Number of tabs in the end of the line |
|
39 const TInt KNumTabsAppended = 2; |
|
40 |
|
41 //help resources |
|
42 //_LIT(KPROV_HLP_CONFCONT,"PROV_HLP_CONFCONT"); |
|
43 const TUint32 KGSUid = 0x100058ec; |
|
44 |
|
45 // ================= MEMBER FUNCTIONS ======================= |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CWPCxContainer::CWPCxContainer |
|
49 // C++ default constructor can NOT contain any code, that |
|
50 // might leave. |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 CWPCxContainer::CWPCxContainer( CWPEngine& aEngine, CAknView& aAppView ) |
|
54 : iEngine( aEngine ), iAppView( aAppView ) |
|
55 { |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CWPCxContainer::ConstructL |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 void CWPCxContainer::ConstructL( const TRect& aRect ) |
|
63 { |
|
64 CreateWindowL(); |
|
65 |
|
66 iListBox = new(ELeave) CAknSingleStyleListBox; |
|
67 iListBox->SetContainerWindowL( *this); |
|
68 |
|
69 // Add vertical scroll bar for the list |
|
70 CEikScrollBarFrame* sbFrame = iListBox->CreateScrollBarFrameL( ETrue ); |
|
71 sbFrame->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, |
|
72 CEikScrollBarFrame::EAuto ); // vertical |
|
73 TResourceReader rr; |
|
74 CEikonEnv::Static()->CreateResourceReaderLC( rr, R_PROVISIONINGCX_LISTBOX ); |
|
75 iListBox->SetContainerWindowL( *this ); |
|
76 iListBox->ConstructFromResourceL( rr ); |
|
77 CleanupStack::PopAndDestroy(); // rr |
|
78 |
|
79 iLines = new(ELeave) CDesCArrayFlat(KLinesGranularity); |
|
80 UpdateContextsL(); |
|
81 |
|
82 iListBox->Model()->SetItemTextArray( iLines ); |
|
83 iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray ); |
|
84 |
|
85 HBufC* emptyText = StringLoader::LoadLC( R_QTN_OP_CONF_CONT_EMPTY ); |
|
86 iListBox->View()->SetListEmptyTextL( *emptyText ); |
|
87 CleanupStack::PopAndDestroy( emptyText ); |
|
88 |
|
89 SetRect(aRect); |
|
90 ActivateL(); |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // Destructor |
|
95 // ----------------------------------------------------------------------------- |
|
96 CWPCxContainer::~CWPCxContainer() |
|
97 { |
|
98 delete iListBox; |
|
99 delete iCxUids; |
|
100 delete iLines; |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CWPCxContainer::CurrentContext |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 TUint32 CWPCxContainer::CurrentContext() const |
|
108 { |
|
109 TInt current( iListBox->CurrentItemIndex() ); |
|
110 |
|
111 TUint32 result( KWPUidNoContext ); |
|
112 if( current >= 0 ) |
|
113 { |
|
114 result = iCxUids->At( current ); |
|
115 } |
|
116 return result; |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CWPCxContainer::CurrentContextName |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 TPtrC CWPCxContainer::CurrentContextName() const |
|
124 { |
|
125 TInt current( iListBox->CurrentItemIndex() ); |
|
126 |
|
127 TPtrC result( iLines->MdcaPoint( current ) ); |
|
128 result.Set( result.Mid( KNumTabsPrepended ) ); |
|
129 result.Set( result.Left( result.Length()-KNumTabsAppended ) ); |
|
130 return result; |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // CWPCxContainer::ContextCount |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 TInt CWPCxContainer::ContextCount() const |
|
138 { |
|
139 return iLines->MdcaCount(); |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CWPCxContainer::UpdateContextsL |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 void CWPCxContainer::UpdateContextsL() |
|
147 { |
|
148 FLOG( _L( "[Provisioning] CWPCxContainer::UpdateContextsL" ) ); |
|
149 |
|
150 delete iCxUids; |
|
151 iCxUids = NULL; |
|
152 iCxUids = iEngine.ContextUidsL(); |
|
153 |
|
154 iLines->Reset(); |
|
155 |
|
156 TInt defaultCount( 0 ); |
|
157 const TInt numUids( iCxUids->Count() ); |
|
158 for( TInt i( 0 ); i < numUids; i++ ) |
|
159 { |
|
160 FLOG( _L( "[Provisioning] CWPCxContainer::UpdateContextsL 1" ) ); |
|
161 TBuf<KMaxLineLength> line; |
|
162 |
|
163 TUint32 uid( iCxUids->At( i ) ); |
|
164 |
|
165 HBufC* tps = iEngine.ContextTPSL( uid ); |
|
166 CleanupStack::PushL( tps ); |
|
167 HBufC* name = iEngine.ContextNameL( uid ); |
|
168 if( name->Length() == 0 ) |
|
169 { |
|
170 FLOG( _L( "[Provisioning] CWPCxContainer::UpdateContextsL name length 0" ) ); |
|
171 delete name; |
|
172 if( defaultCount == 0 ) |
|
173 { |
|
174 name = StringLoader::LoadL( R_QTN_OP_CONTEXT_NAME ); |
|
175 } |
|
176 else |
|
177 { |
|
178 name = StringLoader::LoadL( R_QTN_OP_CONTEXT_NAME2, |
|
179 defaultCount ); |
|
180 } |
|
181 defaultCount++; |
|
182 } |
|
183 CleanupStack::PushL( name ); |
|
184 |
|
185 line.Zero(); |
|
186 line.Append( EKeyTab ); |
|
187 line.Append( *name ); |
|
188 line.Append( EKeyTab ); |
|
189 line.Append( EKeyTab ); |
|
190 |
|
191 CleanupStack::PopAndDestroy( name ); |
|
192 CleanupStack::PopAndDestroy( tps ); |
|
193 |
|
194 iLines->AppendL( line ); |
|
195 } |
|
196 |
|
197 iListBox->HandleItemAdditionL(); |
|
198 |
|
199 TInt index = iListBox->CurrentItemIndex(); |
|
200 TInt count = iListBox->Model()->NumberOfItems(); |
|
201 |
|
202 if ( (index < 0 || index >= count) && count > 0 ) |
|
203 { |
|
204 // sets the last item as focused |
|
205 iListBox->SetCurrentItemIndexAndDraw(count-1); |
|
206 iListBox->HandleItemRemovalL(); |
|
207 } |
|
208 FLOG( _L( "[Provisioning] CWPCxContainer::UpdateContextsL done" ) ); |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // CWPCxContainer::SizeChanged |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 void CWPCxContainer::SizeChanged() |
|
216 { |
|
217 iListBox->SetRect(Rect()); |
|
218 } |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // CWPCxContainer::CountComponentControls |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 TInt CWPCxContainer::CountComponentControls() const |
|
225 { |
|
226 return 1; |
|
227 } |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CWPCxContainer::ComponentControl |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 CCoeControl* CWPCxContainer::ComponentControl( TInt /*aIndex*/ ) const |
|
234 { |
|
235 return iListBox; |
|
236 } |
|
237 |
|
238 // ----------------------------------------------------------------------------- |
|
239 // CWPCxContainer::HandleControlEventL |
|
240 // ----------------------------------------------------------------------------- |
|
241 // |
|
242 void CWPCxContainer::HandleControlEventL( CCoeControl* /*aControl*/, |
|
243 TCoeEvent /*aEventType*/ ) |
|
244 { |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // CWPCxContainer::OfferKeyEventL |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 TKeyResponse CWPCxContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, |
|
252 TEventCode aType) |
|
253 { |
|
254 switch ( aKeyEvent.iCode ) |
|
255 { |
|
256 case EKeyBackspace: |
|
257 { |
|
258 iAppView.ProcessCommandL( EProvisioningCxCmdDeleteContext ); |
|
259 break; |
|
260 } |
|
261 case EKeyOK: |
|
262 { |
|
263 iAppView.ProcessCommandL( EProvisioningCxCmdSelect ); |
|
264 break; |
|
265 } |
|
266 default: |
|
267 { |
|
268 break; |
|
269 } |
|
270 } |
|
271 |
|
272 return iListBox->OfferKeyEventL( aKeyEvent, aType ); |
|
273 } |
|
274 |
|
275 // ----------------------------------------------------------------------------- |
|
276 // CWPCxContainer::GetHelpContext |
|
277 // ----------------------------------------------------------------------------- |
|
278 // |
|
279 void CWPCxContainer::GetHelpContext( TCoeHelpContext& aContext ) const |
|
280 { |
|
281 aContext.iContext = KPROV_HLP_CONFCONT() ; |
|
282 aContext.iMajor=TUid::Uid( KGSUid ); |
|
283 } |
|
284 |
|
285 // --------------------------------------------------------------------------- |
|
286 // CWPCxContainer::HandleResourceChange |
|
287 // |
|
288 // --------------------------------------------------------------------------- |
|
289 |
|
290 void CWPCxContainer::HandleResourceChange( TInt aType ) |
|
291 { |
|
292 if ( aType == KEikDynamicLayoutVariantSwitch ) |
|
293 { |
|
294 TRect mainPaneRect; |
|
295 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, |
|
296 mainPaneRect); |
|
297 SetRect( mainPaneRect ); |
|
298 DrawNow(); |
|
299 } |
|
300 CCoeControl::HandleResourceChange( aType ); |
|
301 } |
|
302 |
|
303 |
|
304 // End of File |
|