pkiutilities/CertmanUi/SRC/CertmanuiviewTrustedSite.cpp
changeset 0 164170e6151a
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 CCertManUIViewTrustedSite
       
    15 *                Updates Options list depending of the number of
       
    16 *                marked and unmarked certificates in the listbox.
       
    17 *                Handles softkey and Option list commands.
       
    18 *                Handles certificate deletion including confirmation note.
       
    19 *                Shows certificate details view with appropriate
       
    20 *                warning notes if certificate is corrupted/expired/not valid.
       
    21 *
       
    22 */
       
    23 
       
    24 
       
    25 // INCLUDE FILES
       
    26 #include <aknmessagequerydialog.h>
       
    27 #include <aknnotewrappers.h>            // for warning & information notes
       
    28 #include <X509CertNameParser.h>
       
    29 #include <ErrorUI.h>
       
    30 #include <x509cert.h>
       
    31 #include <pkixcertchain.h>              //for validation
       
    32 #include <certmanui.rsg>
       
    33 #include "CertmanuiCertificateHelper.h"
       
    34 #include "CertmanuiKeeper.h"
       
    35 #include "CertmanuiviewTrustedSite.h"
       
    36 #include "CertmanuicontainerTrustedSite.h"
       
    37 #include "Certmanui.hrh"
       
    38 #include "CertmanuiSyncWrapper.h"
       
    39 #include "CertmanuiCommon.h"
       
    40 #include "CertManUILogger.h"
       
    41 
       
    42 #include    <hlplch.h>                  // For HlpLauncher
       
    43 #include    <featmgr.h>                 // For FeatureManager
       
    44 
       
    45 
       
    46 // ================= MEMBER FUNCTIONS =======================
       
    47 
       
    48 // ---------------------------------------------------------
       
    49 // CCertManUIViewTrustedSite::CCertManUIViewTrustedSite(CCertManUIKeeper& aKeeper)
       
    50 // : iKeeper(aKeeper), iCrMgr(iKeeper.CertManager())
       
    51 // Constructor
       
    52 // ---------------------------------------------------------
       
    53 //
       
    54 CCertManUIViewTrustedSite::CCertManUIViewTrustedSite( CCertManUIKeeper& aKeeper )
       
    55     : iKeeper( aKeeper )
       
    56     {
       
    57     CERTMANUILOGGER_WRITE_TIMESTAMP(
       
    58         "CCertManUIViewTrustedSite::CCertManUIViewTrustedSite" );
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------
       
    62 // CCertManUIViewTrustedSite::~CCertManUIViewTrustedSite()
       
    63 // Destructor
       
    64 // ---------------------------------------------------------
       
    65 //
       
    66 CCertManUIViewTrustedSite::~CCertManUIViewTrustedSite()
       
    67     {
       
    68     CERTMANUILOGGER_ENTERFN( " CCertManUIViewTrustedSite::~CCertManUIViewTrustedSite" );
       
    69 
       
    70     if ( iContainerTrustedSite )
       
    71         {
       
    72         AppUi()->RemoveFromViewStack( *this, iContainerTrustedSite );
       
    73         delete iContainerTrustedSite;
       
    74         }
       
    75 
       
    76      CERTMANUILOGGER_LEAVEFN( " CCertManUIViewTrustedSite::~CCertManUIViewTrustedSite" );
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------
       
    80 // CCertManUIViewTrustedSite* CCertManUIViewTrustedSite::NewL(
       
    81 //      const TRect& /*aRect*/, CCertManUIKeeper& aKeeper)
       
    82 // ---------------------------------------------------------
       
    83 //
       
    84 CCertManUIViewTrustedSite* CCertManUIViewTrustedSite::NewL(
       
    85     const TRect& /*aRect*/, CCertManUIKeeper& aKeeper )
       
    86     {
       
    87     CCertManUIViewTrustedSite* self =
       
    88         new ( ELeave ) CCertManUIViewTrustedSite( aKeeper );
       
    89     CleanupStack::PushL( self );
       
    90     self->ConstructL();
       
    91     CleanupStack::Pop();
       
    92     return self;
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------
       
    96 // CCertManUIViewTrustedSite* CCertManUIViewTrustedSite::NewLC(
       
    97 //  const TRect& /*aRect*/, CCertManUIKeeper& aKeeper)
       
    98 // ---------------------------------------------------------
       
    99 //
       
   100 CCertManUIViewTrustedSite* CCertManUIViewTrustedSite::NewLC(
       
   101     const TRect& /*aRect*/, CCertManUIKeeper& aKeeper )
       
   102     {
       
   103     CCertManUIViewTrustedSite* self =
       
   104         new ( ELeave ) CCertManUIViewTrustedSite( aKeeper );
       
   105     CleanupStack::PushL( self );
       
   106     self->ConstructL();
       
   107     return self;
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------
       
   111 // CCertManUIViewTrustedSite::ConstructL()
       
   112 // EPOC two-phased constructor
       
   113 // ---------------------------------------------------------
       
   114 //
       
   115 void CCertManUIViewTrustedSite::ConstructL()
       
   116     {
       
   117     CERTMANUILOGGER_ENTERFN( " CCertManUIViewTrustedSite::ConstructL" );
       
   118 
       
   119     BaseConstructL( R_CERTMANUI_VIEW_MAIN_TRUSTED_SITE );
       
   120 
       
   121     CERTMANUILOGGER_LEAVEFN( " CCertManUIViewTrustedSite::ConstructL" );
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------
       
   125 // CCertManUIViewTrustedSite::DynInitMenuPaneL(
       
   126 //      TInt aResourceId,CEikMenuPane* aMenuPane)
       
   127 // Updates Options list with correct items depending on
       
   128 // whether the listbox is empty or if it has any marked items
       
   129 // ---------------------------------------------------------
       
   130 //
       
   131 void CCertManUIViewTrustedSite::DynInitMenuPaneL(
       
   132     TInt aResourceId, CEikMenuPane* aMenuPane )
       
   133     {
       
   134     CERTMANUILOGGER_ENTERFN( " CCertManUIViewTrustedSite::DynInitMenuPaneL" );
       
   135 
       
   136     if (( iKeeper.iWrapper->IsActive()) ||
       
   137         ( iContainerTrustedSite->iListBox->CurrentItemIndex() >= iKeeper.iPeerLabelEntries.Count() ))
       
   138         {
       
   139         return;
       
   140         }
       
   141 
       
   142     const CListBoxView::CSelectionIndexArray* selections =
       
   143             iContainerTrustedSite->iListBox->SelectionIndexes();
       
   144     const TInt markedCount = selections->Count();
       
   145     const TInt currentItemIndex = iContainerTrustedSite->iListBox->CurrentItemIndex();
       
   146 
       
   147     switch ( aResourceId )
       
   148         {
       
   149         case R_CERTMANUI_VIEW_MENU_TRUSTED_SITES:
       
   150             {
       
   151              if( !FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   152                 {
       
   153                 aMenuPane->DeleteMenuItem( EAknCmdHelp );
       
   154                 }
       
   155 
       
   156             // the certificate list is empty, all except Exit are dimmed
       
   157             if ( currentItemIndex == -1 )
       
   158                 {
       
   159                 aMenuPane->SetItemDimmed( ECertManUICmdAppViewDtls, ETrue );
       
   160                 aMenuPane->SetItemDimmed( ECertManUICmdAppDelete, ETrue );
       
   161                 aMenuPane->SetItemDimmed( ECertManUICmdMarkUnmark, ETrue );
       
   162                 }
       
   163             else
       
   164                 {
       
   165                 if ( markedCount > 0 )
       
   166                     {
       
   167                     aMenuPane->SetItemDimmed( ECertManUICmdAppViewDtls, ETrue );
       
   168                     }
       
   169 
       
   170                 if ( !iKeeper.iCertificateHelper->IsOneMarkedCertificateDeletable(
       
   171                         iContainerTrustedSite->iListBox, KCertTypeTrustedSite ) )
       
   172                     {
       
   173                     aMenuPane->SetItemDimmed( ECertManUICmdAppDelete, ETrue );
       
   174                     }
       
   175                 }
       
   176             break;
       
   177             }
       
   178 
       
   179         case R_CERTMANUI_MENUPANE_OPTIONS_MARKED:
       
   180             {
       
   181             if ( !iKeeper.iCertificateHelper->IsOneMarkedCertificateDeletable(
       
   182                     iContainerTrustedSite->iListBox, KCertTypeTrustedSite ) )
       
   183                 {
       
   184                 aMenuPane->SetItemDimmed( ECertManUICmdAppDelete, ETrue );
       
   185                 }
       
   186 
       
   187             // not available for trusted site certificates
       
   188             aMenuPane->SetItemDimmed( ECertManUICmdMoveToDevice, ETrue );
       
   189             aMenuPane->SetItemDimmed( ECertManUICmdMoveToPersonal, ETrue );
       
   190             }
       
   191             // FALLTHROUGH
       
   192 
       
   193         case R_CERTMANUI_MENU_PANE_MARK_UNMARK:
       
   194             {
       
   195             TInt index = 0;
       
   196             TKeyArrayFix key( 0, ECmpTInt );
       
   197             if ( selections->Find( currentItemIndex, key, index ) )
       
   198                 {   // focus is on unmarked item
       
   199                 aMenuPane->SetItemDimmed( ECertManUICmdUnmark, ETrue );
       
   200                 }
       
   201             else
       
   202                 {   // focus is on marked item
       
   203                 aMenuPane->SetItemDimmed( ECertManUICmdMark, ETrue );
       
   204                 }
       
   205 
       
   206             // if all items are marked, dim "mark all" option
       
   207             if ( markedCount == iContainerTrustedSite->iListBox->Model()->NumberOfItems() )
       
   208                 {
       
   209                 aMenuPane->SetItemDimmed( ECertManUICmdMarkAll, ETrue );
       
   210                 }
       
   211 
       
   212             // if no items are marked, dim "unmark all" option
       
   213             if ( markedCount == 0 )
       
   214                 {
       
   215                 aMenuPane->SetItemDimmed( ECertManUICmdUnmarkAll, ETrue );
       
   216                 }
       
   217             break;
       
   218             }
       
   219 
       
   220         default:
       
   221             break;
       
   222         }
       
   223 
       
   224      CERTMANUILOGGER_LEAVEFN( " CCertManUIViewTrustedSite::DynInitMenuPaneL" );
       
   225     }
       
   226 
       
   227 // ---------------------------------------------------------
       
   228 // CCertManUIViewTrustedSite::Id() const
       
   229 // Returns Authority view id
       
   230 // ---------------------------------------------------------
       
   231 //
       
   232 TUid CCertManUIViewTrustedSite::Id() const
       
   233     {
       
   234     return KCertManUIViewTrustedSiteId;
       
   235     }
       
   236 
       
   237 // ---------------------------------------------------------
       
   238 // CCertManUIViewTrustedSite::HandleCommandL(TInt aCommand)
       
   239 // Handles Softkey and Options list commands
       
   240 // ---------------------------------------------------------
       
   241 //
       
   242 void CCertManUIViewTrustedSite::HandleCommandL( TInt aCommand )
       
   243     {
       
   244     CERTMANUILOGGER_ENTERFN( " CCertManUIViewTrustedSite::HandleCommandL" );
       
   245 
       
   246     if (( iKeeper.iWrapper->IsActive() ) ||
       
   247         ( iContainerTrustedSite->iListBox->CurrentItemIndex() >= iKeeper.iPeerLabelEntries.Count() ))
       
   248         {
       
   249         return;
       
   250         }
       
   251 
       
   252     switch ( aCommand )
       
   253         {
       
   254         case EAknSoftkeyBack:
       
   255             {
       
   256             // Activate main view
       
   257             AppUi()->ActivateLocalViewL( KCertManUIViewMainId );
       
   258             break;
       
   259             }
       
   260         // put the view specific menu commands here
       
   261         case EAknCmdExit:
       
   262             {
       
   263             ((CAknViewAppUi*)iAvkonAppUi)->HandleCommandL( EAknCmdExit );
       
   264             break;
       
   265             }
       
   266         case ECertManUICmdAppViewDtls:
       
   267             {
       
   268             iKeeper.iCertificateHelper->MessageQueryViewDetailsL(
       
   269                 iContainerTrustedSite->iListBox->CurrentItemIndex(), KCertTypeTrustedSite, iEikonEnv );
       
   270             break;
       
   271             }
       
   272         case ECertManUICmdAppDelete:
       
   273             {
       
   274             if ( iKeeper.iCertificateHelper->ConfirmationQueryDeleteCertL( KCertTypeTrustedSite,
       
   275                                                     iContainerTrustedSite->iListBox ) )
       
   276                 {
       
   277                 // goes here if at least one certificate is deleted
       
   278                 iCurrentPosition = iContainerTrustedSite->iListBox->CurrentItemIndex();
       
   279                 iTopItem = iContainerTrustedSite->iListBox->TopItemIndex();
       
   280 
       
   281                 iContainerTrustedSite->DrawListBoxL(iCurrentPosition, iTopItem );
       
   282                 TRAPD( error, iKeeper.RefreshPeerCertEntriesL() );
       
   283                 if ( error != KErrNone )
       
   284                     {
       
   285                     if ( error == KErrCorrupt )
       
   286                         {
       
   287                         iKeeper.ShowErrorNoteL( error );
       
   288                         User::Exit( KErrNone );
       
   289                         }
       
   290                     else
       
   291                         {
       
   292                         // have to call straight away the Exit
       
   293                         // showing any error notes would corrupt the display
       
   294                         User::Exit( error );
       
   295                         }
       
   296                     }
       
   297                 UpdateMenuBar();
       
   298                 }
       
   299             break;
       
   300             }
       
   301         case ECertManUICmdMark:
       
   302         case ECertManUICmdUnmark:
       
   303         case ECertManUICmdMarkAll:
       
   304         case ECertManUICmdUnmarkAll:
       
   305             {
       
   306             // Gets pointer of current listbox.
       
   307             CEikListBox* listbox = iContainerTrustedSite->iListBox;
       
   308             if ( listbox )
       
   309                 {
       
   310                 AknSelectionService::HandleMarkableListProcessCommandL(
       
   311                     aCommand, listbox );
       
   312                 iKeeper.iCertificateHelper->HandleMarkableListCommandL(
       
   313                                       aCommand, iContainerTrustedSite->iListBox );
       
   314 
       
   315                 UpdateMenuBar();
       
   316                 }
       
   317 
       
   318             break;
       
   319             }
       
   320         case EAknCmdHelp:
       
   321             {
       
   322             if( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   323                 {
       
   324                 HlpLauncher::LaunchHelpApplicationL(
       
   325                    iEikonEnv->WsSession(), AppUi()->AppHelpContextL() );
       
   326                 }
       
   327 
       
   328             break;
       
   329             }
       
   330 
       
   331         default:
       
   332             {
       
   333             AppUi()->HandleCommandL( aCommand );
       
   334             break;
       
   335             }
       
   336         }
       
   337 
       
   338     CERTMANUILOGGER_LEAVEFN( " CCertManUIViewTrustedSite::HandleCommandL" );
       
   339     }
       
   340 
       
   341 // ---------------------------------------------------------
       
   342 // CCertManUIViewTrustedSite::HandleClientRectChange()
       
   343 // ---------------------------------------------------------
       
   344 //
       
   345 void CCertManUIViewTrustedSite::HandleClientRectChange()
       
   346     {
       
   347     if ( iContainerTrustedSite )
       
   348         {
       
   349         iContainerTrustedSite->SetRect( ClientRect() );
       
   350         }
       
   351     }
       
   352 
       
   353 // ---------------------------------------------------------
       
   354 // CCertManUIViewTrustedSite::DoActivateL(const TVwsViewId& /*aPrevViewId*/,
       
   355 //      TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/)
       
   356 // Updates the view when opening it
       
   357 // ---------------------------------------------------------
       
   358 //
       
   359 void CCertManUIViewTrustedSite::DoActivateL(
       
   360     const TVwsViewId& aPrevViewId,
       
   361     TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/)
       
   362     {
       
   363      CERTMANUILOGGER_ENTERFN( " CCertManUIViewTrustedSite::DoActivateL" );
       
   364 
       
   365      iKeeper.StartWaitDialogL( ECertmanUiWaitDialog );
       
   366      CleanupCloseWaitDialogPushL( iKeeper );
       
   367 
       
   368      TRAPD ( error, iKeeper.RefreshPeerCertEntriesL() );
       
   369      if ( error != KErrNone )
       
   370          {
       
   371          if ( error == KErrCorrupt )
       
   372              {
       
   373              iKeeper.ShowErrorNoteL( error );
       
   374              User::Exit( KErrNone );
       
   375              }
       
   376          else
       
   377              {
       
   378              // have to call straight away the Exit
       
   379              // showing any error notes would corrupt the display
       
   380              User::Exit( error );
       
   381              }
       
   382          }
       
   383 
       
   384     // If this view is being activated from main view,
       
   385     // current position is 0. The declaration of KCertManUIViewMainId is
       
   386     // located in certmanuiviewid.h which is not public header --> constant
       
   387     // is being used.
       
   388     if( aPrevViewId.iViewUid == KCertManUIViewMainId )
       
   389         {
       
   390         iCurrentPosition = 0;
       
   391         }
       
   392 
       
   393     if ( iContainerTrustedSite )
       
   394         {
       
   395         ((CAknViewAppUi*)iAvkonAppUi)->RemoveFromViewStack(
       
   396             *this, iContainerTrustedSite );
       
   397 
       
   398         delete iContainerTrustedSite;
       
   399         iContainerTrustedSite = NULL;
       
   400         }
       
   401     iContainerTrustedSite = new (ELeave) CCertManUIContainerTrustedSite(
       
   402         *this, iKeeper );
       
   403 
       
   404     iContainerTrustedSite->SetMopParent( this );
       
   405     iContainerTrustedSite->ConstructL(
       
   406         ClientRect(), iCurrentPosition, iTopItem );
       
   407 
       
   408     if ( !iKeeper.iCertsDatOK )
       
   409         {
       
   410         iCurrentPosition = 0;
       
   411         iTopItem = 0;
       
   412         }
       
   413 
       
   414     iKeeper.ActivateTitleL( KViewTitleCertManUITrustedSite );
       
   415 
       
   416     iContainerTrustedSite->DrawListBoxL( iCurrentPosition, iTopItem );
       
   417     ((CAknViewAppUi*)iAvkonAppUi)->AddToStackL( *this, iContainerTrustedSite );
       
   418 
       
   419     UpdateMenuBar();
       
   420 
       
   421     CleanupStack::PopAndDestroy();    // closes wait dialog
       
   422 
       
   423     iKeeper.iStartup = EFalse;
       
   424 
       
   425     CERTMANUILOGGER_LEAVEFN( " CCertManUIViewTrustedSite::DoActivateL" );
       
   426     }
       
   427 
       
   428 // ---------------------------------------------------------
       
   429 // CCertManUIViewTrustedSite::DoDeactivate()
       
   430 // Saves focus position when closing view
       
   431 // ---------------------------------------------------------
       
   432 //
       
   433 void CCertManUIViewTrustedSite::DoDeactivate()
       
   434     {
       
   435     CERTMANUILOGGER_ENTERFN( " CCertManUIViewTrustedSite::DoDeactivate" );
       
   436 
       
   437     if ( iKeeper.iCertsDatOK )
       
   438         {
       
   439         iCurrentPosition = iContainerTrustedSite->iListBox->CurrentItemIndex();
       
   440         iTopItem = iContainerTrustedSite->iListBox->TopItemIndex();
       
   441         // do not destroy iContainerTrustedSite here because
       
   442         // TrustSettings view needs it !
       
   443         }
       
   444     else
       
   445         {
       
   446         iCurrentPosition = 0;
       
   447         iTopItem = 0;
       
   448         }
       
   449 
       
   450     CERTMANUILOGGER_LEAVEFN( " CCertManUIViewTrustedSite::DoDeactivate" );
       
   451     }
       
   452 
       
   453 // ---------------------------------------------------------
       
   454 // CCertManUIViewTrustedSite::Container()
       
   455 // Returns iContainerTrustedSite to be used in CertManUiContainerTrustedSite
       
   456 // ---------------------------------------------------------
       
   457 //
       
   458 CCoeControl* CCertManUIViewTrustedSite::Container()
       
   459     {
       
   460     return iContainerTrustedSite;
       
   461     }
       
   462 
       
   463 // ---------------------------------------------------------
       
   464 // CCertManUIViewTrustedSite::UpdateMenuBar()
       
   465 // Updates the menu bar
       
   466 // ---------------------------------------------------------
       
   467 //
       
   468 void CCertManUIViewTrustedSite::UpdateMenuBar()
       
   469     {
       
   470     CEikButtonGroupContainer*  cba = Cba();
       
   471 
       
   472     if ( cba == NULL )
       
   473         {
       
   474         return;
       
   475         }
       
   476 
       
   477     if ( iKeeper.iPeerLabelEntries.Count() == 0 )
       
   478         {
       
   479         // No certificate. Don't show MSK
       
   480         UpdateCba( R_CERTMANUI_OPTIONS_OPEN_BACK );
       
   481         cba->MakeCommandVisible( ECertManUICmdAppViewDtls, EFalse );
       
   482         }
       
   483     else
       
   484         {
       
   485         if ( iContainerTrustedSite->iListBox->SelectionIndexes()->Count() > 0 )
       
   486             {
       
   487             MenuBar()->SetContextMenuTitleResourceId( R_CERTMANUI_MENUBAR_OPTIONS_MARKED );
       
   488             UpdateCba( R_CERTMANUI_OPTIONS_CONTEXT_BACK );
       
   489             }
       
   490         else
       
   491             {
       
   492             MenuBar()->SetMenuTitleResourceId( R_CERTMANUI_MENUBAR_VIEW_TRUSTED_SITES );
       
   493             UpdateCba( R_CERTMANUI_OPTIONS_OPEN_BACK );
       
   494             }
       
   495         cba->MakeCommandVisible( ECertManUICmdAppViewDtls, ETrue );
       
   496         }
       
   497     }
       
   498 
       
   499 // ---------------------------------------------------------
       
   500 // CCertManUIViewTrustedSite::UpdateCba( TInt aCbaResourceId )
       
   501 // Updates cba
       
   502 // ---------------------------------------------------------
       
   503 //
       
   504 void CCertManUIViewTrustedSite::UpdateCba( TInt aCbaResourceId )
       
   505     {
       
   506     CEikButtonGroupContainer*  cba = Cba();
       
   507 
       
   508     if ( cba )
       
   509         {
       
   510         cba->SetCommandSetL( aCbaResourceId );
       
   511         cba->DrawNow();
       
   512         }
       
   513     }
       
   514 
       
   515 
       
   516 // End of File
       
   517 
       
   518 
       
   519