|
1 /* |
|
2 * Copyright (c) 2003-2009 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: Implementation of class CCertManUIContainerAuthority |
|
15 * Reads & updates certificate list |
|
16 * Handles markable list for certificates |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <eikclbd.h> |
|
23 #include <AknIconArray.h> |
|
24 #include <certmanui.rsg> |
|
25 #include <csxhelp/cm.hlp.hrh> // for help context of CertManUI |
|
26 |
|
27 #include "CertmanuiCertificateHelper.h" |
|
28 #include "CertmanuiKeeper.h" |
|
29 #include "CertmanuicontainerAuthority.h" |
|
30 #include "CertmanuiSyncWrapper.h" |
|
31 #include "Certmanui.hrh" |
|
32 #include "CertManUILogger.h" |
|
33 #include "CertmanuiCommon.h" |
|
34 #include "Certmanuidll.h" // for applicationUID |
|
35 |
|
36 // ================= MEMBER FUNCTIONS ======================= |
|
37 |
|
38 // --------------------------------------------------------- |
|
39 // CCertManUIContainerAuthority::CCertManUIContainerAuthority( |
|
40 // CCertManUIViewAuthority& aParent, CCertManUIKeeper& aKeeper ) |
|
41 // Constructor with parent |
|
42 // --------------------------------------------------------- |
|
43 // |
|
44 CCertManUIContainerAuthority::CCertManUIContainerAuthority( |
|
45 CCertManUIViewAuthority& aParent, CCertManUIKeeper& aKeeper ) : |
|
46 iParent ( aParent ), iKeeper ( aKeeper ) |
|
47 { |
|
48 CERTMANUILOGGER_WRITE_TIMESTAMP( |
|
49 "CCertManUIContainerAuthority::CCertManUIContainerAuthority" ); |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------- |
|
53 // CCertManUIContainerAuthority::~CCertManUIContainerAuthority() |
|
54 // Destructor |
|
55 // --------------------------------------------------------- |
|
56 // |
|
57 CCertManUIContainerAuthority::~CCertManUIContainerAuthority() |
|
58 { |
|
59 CERTMANUILOGGER_ENTERFN( |
|
60 " CCertManUIContainerAuthority::~CCertManUIContainerAuthority" ); |
|
61 |
|
62 delete iListBox; |
|
63 |
|
64 CERTMANUILOGGER_LEAVEFN( |
|
65 " CCertManUIContainerAuthority::~CCertManUIContainerAuthority" ); |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------- |
|
69 // CCertManUIContainerAuthority::ConstructL( |
|
70 // const TRect& aRect, TInt& aCurrentPosition, TInt& aTopItem) |
|
71 // EPOC two phased constructor |
|
72 // --------------------------------------------------------- |
|
73 // |
|
74 void CCertManUIContainerAuthority::ConstructL( |
|
75 const TRect& aRect, TInt& aCurrentPosition, TInt& aTopItem ) |
|
76 { |
|
77 CERTMANUILOGGER_ENTERFN( " CCertManUIContainerAuthority::ConstructL" ); |
|
78 |
|
79 CreateWindowL(); |
|
80 CreateListBoxL(); |
|
81 UpdateListBoxL( aCurrentPosition, aTopItem ); |
|
82 if ( iListBox ) |
|
83 { |
|
84 // Creates graphic. |
|
85 iListBox->ItemDrawer()->ColumnData()-> |
|
86 SetIconArray( iIconHandler->CreateIconArrayL() ); |
|
87 } |
|
88 SetRect( aRect ); |
|
89 |
|
90 CERTMANUILOGGER_LEAVEFN( " CCertManUIContainerAuthority::ConstructL" ); |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------- |
|
94 // CCertManUIContainerAuthority::SizeChanged() |
|
95 // Called by framework when the view size is changed |
|
96 // --------------------------------------------------------- |
|
97 // |
|
98 void CCertManUIContainerAuthority::SizeChanged() |
|
99 { |
|
100 iListBox->SetRect( Rect() ); |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------- |
|
104 // CCertManUIContainerAuthority::FocusChanged( TDrawNow aDrawNow ) |
|
105 // --------------------------------------------------------- |
|
106 // |
|
107 void CCertManUIContainerAuthority::FocusChanged( TDrawNow aDrawNow ) |
|
108 { |
|
109 if ( iListBox ) |
|
110 { |
|
111 iListBox->SetFocus( IsFocused(), aDrawNow ); |
|
112 } |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------- |
|
116 // CCertManUIContainerAuthority::HandleListBoxEventL( |
|
117 // CEikListBox* /*aListBox*/, TListBoxEvent aEventType) |
|
118 // --------------------------------------------------------- |
|
119 // |
|
120 void CCertManUIContainerAuthority::HandleListBoxEventL( |
|
121 CEikListBox* /*aListBox*/, TListBoxEvent aEventType ) |
|
122 { |
|
123 CERTMANUILOGGER_ENTERFN( " CCertManUIContainerAuthority::HandleListBoxEventL" ); |
|
124 |
|
125 switch ( aEventType ) |
|
126 { |
|
127 case EEventItemDoubleClicked: |
|
128 case EEventItemSingleClicked: |
|
129 case EEventEnterKeyPressed: |
|
130 { |
|
131 const CListBoxView::CSelectionIndexArray* selections = iListBox->SelectionIndexes(); |
|
132 if ( iListItemCount > 0 ) |
|
133 { |
|
134 TInt currentItemIndex = iListBox->CurrentItemIndex(); |
|
135 if ( selections->Count() == 0 ) |
|
136 { |
|
137 iKeeper.iCertificateHelper->MessageQueryViewDetailsL( |
|
138 currentItemIndex, KCertTypeAuthority, iEikonEnv ); |
|
139 } |
|
140 else |
|
141 { |
|
142 CEikMenuBar* menuBar = iParent.MenuBar(); |
|
143 menuBar->SetContextMenuTitleResourceId( R_CERTMANUI_MENUBAR_OPTIONS_MARKED ); |
|
144 menuBar->TryDisplayContextMenuBarL(); |
|
145 } |
|
146 } |
|
147 break; |
|
148 } |
|
149 |
|
150 default: |
|
151 { |
|
152 break; |
|
153 } |
|
154 } |
|
155 |
|
156 CERTMANUILOGGER_LEAVEFN( " CCertManUIContainerAuthority::HandleListBoxEventL" ); |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------- |
|
160 // CCertManUIContainerAuthority::CountComponentControls() const |
|
161 // --------------------------------------------------------- |
|
162 // |
|
163 TInt CCertManUIContainerAuthority::CountComponentControls() const |
|
164 { |
|
165 // return number of controls inside this container |
|
166 return 1; |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------- |
|
170 // CCertManUIContainerAuthority::ComponentControl( |
|
171 // TInt /*aIndex*/) const |
|
172 // --------------------------------------------------------- |
|
173 // |
|
174 CCoeControl* CCertManUIContainerAuthority::ComponentControl( |
|
175 TInt /*aIndex*/) const |
|
176 { |
|
177 return iListBox; |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------- |
|
181 // CCertManUIContainerAuthority::Draw(const TRect& aRect) const |
|
182 // --------------------------------------------------------- |
|
183 // |
|
184 void CCertManUIContainerAuthority::Draw( const TRect& aRect ) const |
|
185 { |
|
186 CWindowGc& gc = SystemGc(); |
|
187 gc.SetPenStyle( CGraphicsContext::ENullPen ); |
|
188 gc.SetBrushColor( KRgbGray ); |
|
189 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
190 gc.DrawRect( aRect ); |
|
191 } |
|
192 |
|
193 // --------------------------------------------------------- |
|
194 // CCertManUIContainerAuthority::HandleControlEventL( |
|
195 // CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/) |
|
196 // Cannot be changed to non-leaving function. |
|
197 // L-function is required by the class definition, even if empty. |
|
198 // --------------------------------------------------------- |
|
199 // |
|
200 void CCertManUIContainerAuthority::HandleControlEventL( |
|
201 CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/) |
|
202 { |
|
203 } |
|
204 |
|
205 // --------------------------------------------------------- |
|
206 // CCertManUIContainerAuthority::OfferKeyEventL( |
|
207 // const TKeyEvent& aKeyEvent, TEventCode aType) |
|
208 // Handles the key events arrow keys, delete key. |
|
209 // --------------------------------------------------------- |
|
210 // |
|
211 TKeyResponse CCertManUIContainerAuthority::OfferKeyEventL( |
|
212 const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
213 { |
|
214 CERTMANUILOGGER_ENTERFN( " CCertManUIContainerAuthority::OfferKeyEventL" ); |
|
215 |
|
216 // If operation is currenly onway, do not continue. |
|
217 if ( iKeeper.iWrapper->IsActive() ) |
|
218 { |
|
219 return EKeyWasNotConsumed; |
|
220 } |
|
221 |
|
222 TKeyResponse retval = EKeyWasNotConsumed; |
|
223 if ( aType==EEventKey ) |
|
224 { |
|
225 if ( aKeyEvent.iCode == EKeyRightArrow ) |
|
226 { |
|
227 ((CAknViewAppUi*)iAvkonAppUi)->ActivateLocalViewL( |
|
228 KCertManUIViewTrustedSiteId ); |
|
229 retval = EKeyWasConsumed; |
|
230 } |
|
231 else if ( aKeyEvent.iCode == EKeyLeftArrow ) |
|
232 { |
|
233 ((CAknViewAppUi*)iAvkonAppUi)->ActivateLocalViewL( |
|
234 KCertManUIViewDeviceId ); |
|
235 retval = EKeyWasConsumed; |
|
236 } |
|
237 else if ( aKeyEvent.iCode == EKeyDelete |
|
238 || aKeyEvent.iCode == EKeyBackspace ) |
|
239 { |
|
240 TInt currentItemAuthority = iListBox->CurrentItemIndex(); |
|
241 |
|
242 if ( ( currentItemAuthority >= 0 ) && |
|
243 ( currentItemAuthority < iKeeper.iCALabelEntries.Count())) |
|
244 { |
|
245 // list is not empty |
|
246 if ( iKeeper.iCertificateHelper->ConfirmationQueryDeleteCertL( |
|
247 KCertTypeAuthority, iListBox ) ) // == ETrue |
|
248 { |
|
249 |
|
250 iParent.iCurrentPosition = iListBox->CurrentItemIndex(); |
|
251 iParent.iTopItem = iListBox->TopItemIndex(); |
|
252 |
|
253 DrawListBoxL(iParent.iCurrentPosition, iParent.iTopItem ); |
|
254 // goes here if at least one certificate is deleted |
|
255 TRAPD( error, iKeeper.RefreshCAEntriesL() ); |
|
256 if ( error != KErrNone ) |
|
257 { |
|
258 if ( error == KErrCorrupt ) |
|
259 { |
|
260 iKeeper.ShowErrorNoteL( error ); |
|
261 User::Exit( KErrNone ); |
|
262 } |
|
263 else |
|
264 { |
|
265 // have to call straight away the Exit |
|
266 // showing any error notes would corrupt the display |
|
267 User::Exit( error ); |
|
268 } |
|
269 } |
|
270 iParent.UpdateMenuBar(); |
|
271 } |
|
272 } |
|
273 // Listbox takes all event even if it doesn't use them |
|
274 retval = EKeyWasConsumed; |
|
275 } |
|
276 else |
|
277 { |
|
278 retval = iListBox->OfferKeyEventL( aKeyEvent, aType ); |
|
279 } |
|
280 |
|
281 } |
|
282 else |
|
283 { |
|
284 retval = iListBox->OfferKeyEventL( aKeyEvent, aType ); |
|
285 } |
|
286 |
|
287 if ( iListBox->SelectionIndexes()->Count() > 0 ) |
|
288 { |
|
289 iParent.MenuBar()->SetContextMenuTitleResourceId( |
|
290 R_CERTMANUI_MENUBAR_OPTIONS_MARKED ); |
|
291 iParent.UpdateCba( R_CERTMANUI_OPTIONS_CONTEXT_BACK ); |
|
292 } |
|
293 else |
|
294 { |
|
295 iParent.MenuBar()->SetMenuTitleResourceId( R_CERTMANUI_MENUBAR_VIEW_AUTHORITY ); |
|
296 iParent.UpdateCba( R_CERTMANUI_OPTIONS_OPEN_BACK ); |
|
297 } |
|
298 |
|
299 CERTMANUILOGGER_LEAVEFN( " CCertManUIContainerAuthority::OfferKeyEventL" ); |
|
300 |
|
301 return retval; |
|
302 } |
|
303 |
|
304 // --------------------------------------------------------- |
|
305 // CCertManUIContainerAuthority::CreateListBoxL() |
|
306 // Creates listbox, sets empty listbox text. |
|
307 // --------------------------------------------------------- |
|
308 // |
|
309 void CCertManUIContainerAuthority::CreateListBoxL() |
|
310 { |
|
311 CERTMANUILOGGER_ENTERFN( " CCertManUIContainerAuthority::CreateListBoxL()" ); |
|
312 |
|
313 iListBox = new( ELeave ) CAknSingleStyleListBox; |
|
314 iListBox->SetContainerWindowL( *this ); |
|
315 iListBox->ConstructL( this, EAknListBoxMarkableList ); |
|
316 iListBox->CreateScrollBarFrameL( ETrue ); |
|
317 iListBox->ScrollBarFrame()-> |
|
318 SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto ); |
|
319 iListBox->SetListBoxObserver( this ); |
|
320 |
|
321 HBufC* stringHolder = StringLoader::LoadLC( |
|
322 R_TEXT_RESOURCE_VIEW_AUTHORITY_EMPTY_LIST ); |
|
323 iListBox->View()->SetListEmptyTextL( *stringHolder ); |
|
324 CleanupStack::PopAndDestroy(); // stringHolder |
|
325 |
|
326 CERTMANUILOGGER_LEAVEFN( " CCertManUIContainerAuthority::CreateListBoxL()" ); |
|
327 } |
|
328 |
|
329 // --------------------------------------------------------- |
|
330 // CCertManUIContainerAuthority::DrawListBoxL(TInt aCurrentPosition, TInt aTopItem) |
|
331 // Draws listbox, fetches graphic icons for markable list |
|
332 // --------------------------------------------------------- |
|
333 // |
|
334 void CCertManUIContainerAuthority::DrawListBoxL( |
|
335 TInt aCurrentPosition, TInt aTopItem ) |
|
336 { |
|
337 CERTMANUILOGGER_ENTERFN( " CCertManUIContainerAuthority::DrawListBoxL" ); |
|
338 |
|
339 if ( aCurrentPosition >= 0 ) |
|
340 { |
|
341 iListBox->SetTopItemIndex( aTopItem ); |
|
342 iListBox->SetCurrentItemIndex( aCurrentPosition ); |
|
343 } |
|
344 |
|
345 ActivateL(); |
|
346 DrawNow(); |
|
347 |
|
348 CERTMANUILOGGER_LEAVEFN( " CCertManUIContainerAuthority::DrawListBoxL" ); |
|
349 } |
|
350 |
|
351 // --------------------------------------------------------- |
|
352 // CCertManUIContainerAuthority::UpdateListBoxL(TInt& aCurrentPosition, TInt& aTopItem) |
|
353 // Gets list of certificates from CertManAPI, displays them, |
|
354 // sets No label/No subject text to them if their names are empty |
|
355 // --------------------------------------------------------- |
|
356 // |
|
357 void CCertManUIContainerAuthority::UpdateListBoxL( |
|
358 TInt& aCurrentPosition, TInt& aTopItem ) |
|
359 { |
|
360 CERTMANUILOGGER_ENTERFN( " CCertManUIContainerAuthority::UpdateListBoxL()" ); |
|
361 |
|
362 iKeeper.StartWaitDialogL( ECertmanUiWaitDialog ); |
|
363 CleanupCloseWaitDialogPushL( iKeeper ); |
|
364 |
|
365 MDesCArray* itemList = iListBox->Model()->ItemTextArray(); |
|
366 CDesCArray* itemArray = ( CDesCArray* )itemList; |
|
367 |
|
368 // List CA certificates |
|
369 if ( iKeeper.iCertsDatOK ) // == ETrue |
|
370 { |
|
371 // cacerts.dat is not corrupted, get count |
|
372 iListItemCount = iKeeper.iCALabelEntries.Count(); |
|
373 } |
|
374 else |
|
375 { |
|
376 iListItemCount = 0; |
|
377 } |
|
378 if (iListItemCount == 0 ) //list is empty, disable the scroll bar |
|
379 { |
|
380 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
381 CEikScrollBarFrame::EOff,CEikScrollBarFrame::EOff); |
|
382 } |
|
383 if ( iListItemCount > 0 ) |
|
384 { |
|
385 if ( ( aCurrentPosition == -1 ) |
|
386 || ( aCurrentPosition > iListItemCount-1 ) ) |
|
387 { |
|
388 aCurrentPosition = 0; |
|
389 aTopItem = 0; |
|
390 } |
|
391 |
|
392 HBufC* buf = HBufC::NewLC( KMaxLengthTextCertLabel ); |
|
393 for ( TInt i = 0; i < iListItemCount; i++ ) |
|
394 { |
|
395 buf->Des() = ( iKeeper.iCALabelEntries )[i]->iCAEntryLabel->Des(); |
|
396 |
|
397 TPtrC trimmedCertLabel = iKeeper.iCertificateHelper->CutCertificateField( buf->Des() ); |
|
398 buf->Des().Copy( trimmedCertLabel ); |
|
399 TInt length = buf->Des().Length(); |
|
400 if ( length == 0 ) |
|
401 { |
|
402 HBufC* stringHolder = NULL; |
|
403 |
|
404 stringHolder = StringLoader::LoadLC( |
|
405 R_TEXT_RESOURCE_VIEW_NO_SUBJECT_LIST ); |
|
406 |
|
407 itemArray->AppendL( *stringHolder ); |
|
408 CleanupStack::PopAndDestroy(); // stringHolder |
|
409 } |
|
410 else |
|
411 { |
|
412 buf->Des().Insert(0, KCertManUIInsertDescriptor); |
|
413 itemArray->AppendL(buf->Des()); |
|
414 } |
|
415 iListBox->HandleItemAdditionL(); |
|
416 } |
|
417 CleanupStack::PopAndDestroy(); // buf |
|
418 } |
|
419 |
|
420 CleanupStack::PopAndDestroy(); // closes wait dialog |
|
421 |
|
422 CERTMANUILOGGER_LEAVEFN( " CCertManUIContainerAuthority::UpdateListBoxL()" ); |
|
423 } |
|
424 |
|
425 // --------------------------------------------------------- |
|
426 // CCertManUIContainerAuthority::HandleResourceChange |
|
427 // |
|
428 // --------------------------------------------------------- |
|
429 // |
|
430 void CCertManUIContainerAuthority::HandleResourceChange( TInt aType ) |
|
431 { |
|
432 CCoeControl::HandleResourceChange( aType ); |
|
433 |
|
434 if ( aType == KEikDynamicLayoutVariantSwitch ) |
|
435 { |
|
436 TRect mainPaneRect; |
|
437 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPaneRect ); |
|
438 SetRect( mainPaneRect ); |
|
439 DrawNow(); |
|
440 } |
|
441 } |
|
442 |
|
443 // --------------------------------------------------------- |
|
444 // CCertManUIContainerAuthority::IconArrayResourceId |
|
445 // Loads Mark/Unmark icons from resource |
|
446 // --------------------------------------------------------- |
|
447 // |
|
448 TInt CCertManUIContainerAuthority::IconArrayResourceId() const |
|
449 { |
|
450 return R_CERTMANUI_CERTIFICATE_LISTBOX_MARK_ICONS; |
|
451 } |
|
452 |
|
453 // --------------------------------------------------------- |
|
454 // CCertManUIContainerAuthority::CreateIconArrayL |
|
455 // Creates Icon Array |
|
456 // --------------------------------------------------------- |
|
457 // |
|
458 CAknIconArray* CCertManUIContainerAuthority::CreateIconArrayL() const |
|
459 { |
|
460 CAknIconArray* icons = new (ELeave) CAknIconArray( KGranularity ); |
|
461 CleanupStack::PushL( icons ); |
|
462 icons->ConstructFromResourceL( IconArrayResourceId() ); |
|
463 CleanupStack::Pop(); // icons |
|
464 return icons; |
|
465 } |
|
466 |
|
467 // --------------------------------------------------------- |
|
468 // CCertManUIContainerAuthority::GetHelpContext |
|
469 // This function is called when Help application is launched. |
|
470 // (other items were commented in a header). |
|
471 // --------------------------------------------------------- |
|
472 // |
|
473 void CCertManUIContainerAuthority::GetHelpContext( |
|
474 TCoeHelpContext& aContext ) const |
|
475 { |
|
476 aContext.iMajor = KUidCM; |
|
477 aContext.iContext = KCM_HLP_AUTHORITY; |
|
478 } |
|
479 |
|
480 // End of File |