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