pkiutilities/CertmanUi/SRC/CertmanuicontainerTrust.cpp
changeset 0 164170e6151a
child 10 ece4bbb094df
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 CCertManUIContainerTrust.
       
    15 *                Maintains correct list of trusted clients depending
       
    16 *                on the certificate that was in focus in Authority
       
    17 *                certificates view when Trust Settings view was entered.
       
    18 *                Shows and changes correct Yes/No text for the Trusted client.
       
    19 *
       
    20 */
       
    21 
       
    22 
       
    23 // INCLUDE FILES
       
    24 #include <certificateapps.h>
       
    25 #include <mctcertapps.h>
       
    26 #include <mctcertstore.h>
       
    27 #include <csxhelp/cm.hlp.hrh>   // for help context of CertManUI
       
    28 #include <certmanui.rsg>
       
    29 
       
    30 #include "CertmanuiKeeper.h"
       
    31 #include "CertmanuiviewTrust.h"
       
    32 #include "CertmanuicontainerTrust.h"
       
    33 #include "Certmanuitrustids.h"
       
    34 #include "CertmanuiSyncWrapper.h"
       
    35 #include "CertManUILogger.h"
       
    36 #include "CertmanuiCommon.h"
       
    37 #include "CertManUILogger.h"
       
    38 
       
    39 #include "Certmanuidll.h"     // for applicationUID
       
    40 
       
    41 
       
    42 const TInt KMidpCertStoreUid = 0x101F5B71;
       
    43 
       
    44 // ============================= LOCAL FUNCTIONS ===============================
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // void CloseAndDeleteRArray( TAny* aPointer )
       
    48 // Function frees resources of a RArray.
       
    49 // Returns: void
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 void CloseAndDeleteRArray( TAny* aPointer )
       
    53     {
       
    54     ((RArray<TUid>*)aPointer)->Close();
       
    55     delete ( (RArray<TUid>*)aPointer );
       
    56     }
       
    57 
       
    58 // ================= MEMBER FUNCTIONS =======================
       
    59 
       
    60 // ---------------------------------------------------------
       
    61 // CCertManUIContainerTrust::CCertManUIContainerTrust(
       
    62 //                              CCertManUIViewTrust& aParent,
       
    63 //                              CCertManUIKeeper& aKeeper)
       
    64 // Constructor with parent
       
    65 // ---------------------------------------------------------
       
    66 //
       
    67 CCertManUIContainerTrust::CCertManUIContainerTrust(
       
    68     CCertManUIViewTrust& aParent,
       
    69     CCertManUIKeeper& aKeeper )
       
    70     : iParent ( aParent ), iKeeper ( aKeeper )
       
    71     {
       
    72     CERTMANUILOGGER_WRITE_TIMESTAMP(
       
    73         "CCertManUIContainerTrust::CCertManUIContainerTrust" );
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------
       
    77 // CCertManUIContainerTrust::~CCertManUIContainerTrust()
       
    78 // Destructor
       
    79 // ---------------------------------------------------------
       
    80 //
       
    81 CCertManUIContainerTrust::~CCertManUIContainerTrust()
       
    82     {
       
    83     CERTMANUILOGGER_ENTERFN(
       
    84         " CCertManUIContainerTrust::~CCertManUIContainerTrust" );
       
    85 
       
    86     delete iListBox;
       
    87     delete iTrustedClients;
       
    88     delete iTrustValues;
       
    89     delete iAppInfoManager;
       
    90     iClientUids.Close();
       
    91 
       
    92     CERTMANUILOGGER_LEAVEFN(
       
    93         " CCertManUIContainerTrust::~CCertManUIContainerTrust" );
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------
       
    97 // CCertManUIContainerTrust::ConstructL(const TRect& aRect)
       
    98 // EPOC two phased constructor
       
    99 // ---------------------------------------------------------
       
   100 //
       
   101 void CCertManUIContainerTrust::ConstructL(const TRect& aRect)
       
   102     {
       
   103     CERTMANUILOGGER_ENTERFN( " CCertManUIContainerTrust::ConstructL" );
       
   104 
       
   105     CreateWindowL();
       
   106     CreateListBoxL();
       
   107     SetRect(aRect);
       
   108     iTrustedClients = iCoeEnv->ReadDesC16ArrayResourceL(
       
   109           R_CERTMANUI_VIEW_TRUST_SETTINGS_LISTBOX );
       
   110     iTrustValues = iCoeEnv->ReadDesC16ArrayResourceL(
       
   111           R_CERTMANUI_TRUST_SETTINGS_VALUES );
       
   112 
       
   113     TRAPD( error, iAppInfoManager =
       
   114         CCertificateAppInfoManager::NewL( iKeeper.iRfs, EFalse ) );
       
   115     if ( error != KErrNone )
       
   116         {
       
   117         if ( error == KErrNotSupported
       
   118             || error == KErrCorrupt
       
   119             || error == KErrNotReady
       
   120             || error == KErrArgument
       
   121             || error == KErrNotFound )
       
   122             {
       
   123             iKeeper.ShowErrorNoteL( error );
       
   124             User::Exit( KErrNone );
       
   125             }
       
   126         else
       
   127             {
       
   128             User::Leave( error );
       
   129             }
       
   130         }
       
   131 
       
   132     CERTMANUILOGGER_LEAVEFN( " CCertManUIContainerTrust::ConstructL" );
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------
       
   136 // CCertManUIContainerTrust::SizeChanged()
       
   137 // Called by framework when the view size is changed
       
   138 // ---------------------------------------------------------
       
   139 //
       
   140 void CCertManUIContainerTrust::SizeChanged()
       
   141     {
       
   142     iListBox->SetRect( Rect() );
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------
       
   146 // CCertManUIContainerTrust::FocusChanged(TDrawNow aDrawNow)
       
   147 // ---------------------------------------------------------
       
   148 //
       
   149 void CCertManUIContainerTrust::FocusChanged( TDrawNow aDrawNow )
       
   150     {
       
   151     if ( iListBox )
       
   152         {
       
   153         iListBox->SetFocus( IsFocused(), aDrawNow );
       
   154         }
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------
       
   158 // CCertManUIContainerTrust::HandleListBoxEventL(
       
   159 //      CEikListBox* /*aListBox*/, TListBoxEvent /*aEventType*/)
       
   160 // Cannot be changed to non-leaving function.
       
   161 // L-function is required by the class definition, even if empty.
       
   162 // ---------------------------------------------------------
       
   163 //
       
   164 void CCertManUIContainerTrust::HandleListBoxEventL(
       
   165     CEikListBox* /*aListBox*/, TListBoxEvent aEventType )
       
   166     {
       
   167     CERTMANUILOGGER_ENTERFN(
       
   168       " CCertManUIContainerTrust::HandleListBoxEventL" );
       
   169 
       
   170     switch( aEventType )
       
   171         {
       
   172         case EEventItemSingleClicked:
       
   173             if ( !iKeeper.iWrapper->IsActive() )
       
   174                 {
       
   175                 iParent.ChangeTrustL();
       
   176                 }
       
   177             break;
       
   178         default:
       
   179             {
       
   180             break;
       
   181             }
       
   182         }
       
   183 
       
   184     CERTMANUILOGGER_LEAVEFN(
       
   185       " CCertManUIContainerTrust::HandleListBoxEventL" );
       
   186     }
       
   187 
       
   188 
       
   189 // ---------------------------------------------------------
       
   190 // CCertManUIContainerTrust::CountComponentControls() const
       
   191 // ---------------------------------------------------------
       
   192 //
       
   193 TInt CCertManUIContainerTrust::CountComponentControls() const
       
   194     {
       
   195     // return number of controls inside this container
       
   196     return 1;
       
   197     }
       
   198 
       
   199 // ---------------------------------------------------------
       
   200 // CCertManUIContainerTrust::ComponentControl(TInt /*aIndex*/) const
       
   201 // ---------------------------------------------------------
       
   202 //
       
   203 CCoeControl* CCertManUIContainerTrust::ComponentControl(
       
   204     TInt /*aIndex*/ ) const
       
   205     {
       
   206     return iListBox;
       
   207     }
       
   208 
       
   209 // ---------------------------------------------------------
       
   210 // CCertManUIContainerTrust::Draw(const TRect& aRect) const
       
   211 // ---------------------------------------------------------
       
   212 //
       
   213 void CCertManUIContainerTrust::Draw( const TRect& aRect ) const
       
   214     {
       
   215     CWindowGc& gc = SystemGc();
       
   216     gc.SetPenStyle( CGraphicsContext::ENullPen );
       
   217     gc.SetBrushColor( KRgbGray );
       
   218     gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   219     gc.DrawRect( aRect );
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------
       
   223 // CCertManUIContainerTrust::HandleControlEventL(
       
   224 //    CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
       
   225 // Cannot be changed to non-leaving function.
       
   226 // L-function is required by the class definition, even if empty.
       
   227 // ---------------------------------------------------------
       
   228 //
       
   229 void CCertManUIContainerTrust::HandleControlEventL(
       
   230     CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/ )
       
   231     {
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------
       
   235 // CCertManUIContainerTrust::OfferKeyEventL(const TKeyEvent& aKeyEvent,
       
   236 //      TEventCode aType)
       
   237 // Handles the key events OK button, arrow keys.
       
   238 // ---------------------------------------------------------
       
   239 //
       
   240 TKeyResponse CCertManUIContainerTrust::OfferKeyEventL(
       
   241     const TKeyEvent& aKeyEvent,
       
   242     TEventCode aType )
       
   243     {
       
   244     CERTMANUILOGGER_ENTERFN( " CCertManUIContainerTrust::OfferKeyEventL" );
       
   245 
       
   246     TBool doRet = EFalse;
       
   247 
       
   248     switch ( aKeyEvent.iCode )
       
   249         {
       
   250         case EKeyOK:
       
   251             {
       
   252             if ( !iKeeper.iWrapper->IsActive() )
       
   253                 {
       
   254                 iParent.ChangeTrustL();
       
   255                 }
       
   256             break;
       
   257             }
       
   258         case EKeyLeftArrow:
       
   259         case EKeyRightArrow:
       
   260             {
       
   261             // Listbox takes all event even if it doesn't use them
       
   262             doRet = ETrue;
       
   263             break;
       
   264             }
       
   265         default:
       
   266             {
       
   267             break;
       
   268             }
       
   269         }
       
   270 
       
   271     CERTMANUILOGGER_LEAVEFN( " CCertManUIContainerTrust::OfferKeyEventL" );
       
   272 
       
   273     if ( doRet )
       
   274         {
       
   275         return EKeyWasConsumed;
       
   276         }
       
   277 
       
   278     return iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   279     }
       
   280 
       
   281 // ---------------------------------------------------------
       
   282 // CCertManUIContainerTrust::CreateListBoxL()
       
   283 // Creates listbox
       
   284 // ---------------------------------------------------------
       
   285 //
       
   286 void CCertManUIContainerTrust::CreateListBoxL()
       
   287     {
       
   288     CERTMANUILOGGER_ENTERFN( " CCertManUIContainerTrust::CreateListBoxL" );
       
   289 
       
   290     iListBox = new ( ELeave ) CAknSettingStyleListBox;
       
   291     iListBox->SetContainerWindowL( *this );
       
   292     iListBox->ConstructL( this, EAknListBoxSelectionList );
       
   293     iListBox->CreateScrollBarFrameL( ETrue );
       
   294     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   295           CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto );
       
   296     iListBox->SetListBoxObserver( this );
       
   297 
       
   298     CERTMANUILOGGER_LEAVEFN( " CCertManUIContainerTrust::CreateListBoxL" );
       
   299     }
       
   300 
       
   301 // ---------------------------------------------------------
       
   302 // CCertManUIContainerTrust::DrawListBoxL(
       
   303 //      TInt aCurrentPosition, TInt aTopItem, TInt aCertificateIndex)
       
   304 // Draws listbox
       
   305 // ---------------------------------------------------------
       
   306 //
       
   307 void CCertManUIContainerTrust::DrawListBoxL(
       
   308     TInt aCurrentPosition, TInt aTopItem, TInt aCertificateIndex)
       
   309     {
       
   310     CERTMANUILOGGER_ENTERFN( " CCertManUIContainerTrust::DrawListBoxL" );
       
   311 
       
   312     iListBox->SetTopItemIndex( aTopItem );
       
   313     iListBox->SetCurrentItemIndex( aCurrentPosition );
       
   314     UpdateListBoxL( aCertificateIndex );
       
   315     ActivateL();
       
   316     DrawNow();
       
   317 
       
   318     CERTMANUILOGGER_LEAVEFN( " CCertManUIContainerTrust::DrawListBoxL" );
       
   319     }
       
   320 
       
   321 // ---------------------------------------------------------------------------
       
   322 // CCertManUIContainerTrust::UpdateListBoxL(TInt aCertificateIndex)
       
   323 // Puts correct Trust Settings text to listbox and correct value (yes/no)
       
   324 // to the setting, asks the value from CheckCertificateClientTrust
       
   325 // For X509 certificates, only one Application is currently supported
       
   326 // (Application controller), more applications maybe added later however,
       
   327 // so one additional application has been left in comments as an example.
       
   328 // WAP connection and Application installer have their names from resources
       
   329 // and thus localized,  other additional application get their names from
       
   330 // TCertificateAppInfo's Name() function.
       
   331 // ---------------------------------------------------------------------------
       
   332 //
       
   333 void CCertManUIContainerTrust::UpdateListBoxL( TInt aCertificateIndex )
       
   334     {
       
   335     CERTMANUILOGGER_ENTERFN( " CCertManUIContainerTrust::UpdateListBoxL" );
       
   336 
       
   337     SetEmptyListL( iListBox );
       
   338 
       
   339     iApps.Reset();
       
   340     iClientUids.Reset();
       
   341 
       
   342     TInt clientCount = 0;
       
   343 
       
   344     // Use certificate index from previous view
       
   345     CCTCertInfo* entry = iKeeper.iCALabelEntries[ aCertificateIndex ]->iCAEntry;
       
   346 
       
   347     // Here MCTCertApps should be used to get client options, but it is not properly
       
   348     // supported in any cert store. It should be possible to get the MCTCertApps
       
   349     // through token's GetInterface function.
       
   350     if ( entry->Token().TokenType().Type() == TUid::Uid( KTokenTypeFileCertstore ) )
       
   351         {
       
   352         if ( !iAppInfoManager )
       
   353             {
       
   354             User::Leave( KErrArgument );
       
   355             }
       
   356         iApps = iAppInfoManager->Applications();
       
   357         for ( TInt i = 0; i < iApps.Count(); i++ )
       
   358             {
       
   359             if ( iApps[i].Id() != KCertManUIViewTrustJavaInstallingId &&
       
   360                  iApps[i].Id() != KCertManUIViewTrustApplicationControllerId )
       
   361                 {
       
   362                 iClientUids.Append( iApps[i].Id() );
       
   363                 }
       
   364             }
       
   365         }
       
   366     else
       
   367         {
       
   368         iKeeper.iWrapper->GetApplicationsL(
       
   369                 iKeeper.CertManager(), *entry, iClientUids );
       
   370         }
       
   371 
       
   372     // This is needed because MIDPCertStore does not support MCTCertApps
       
   373     if ( iClientUids.Count() == 0 &&
       
   374         entry->Token().TokenType().Type() == TUid::Uid( KMidpCertStoreUid ) )
       
   375         {
       
   376         iClientUids.Append( KCertManUIViewTrustJavaInstallingId );
       
   377         }
       
   378 
       
   379     clientCount = iClientUids.Count();
       
   380 
       
   381 
       
   382     MDesCArray* itemList = iListBox->Model()->ItemTextArray();
       
   383     CDesCArray* itemArray = STATIC_CAST( CDesCArray*, itemList );
       
   384     if ( EX509Certificate == entry->CertificateFormat() )
       
   385         {
       
   386         TInt resIndex = KErrNotFound;
       
   387         TInt position = 0;
       
   388         if ( iClientUids.Count() > 0 )
       
   389             {
       
   390             for ( TInt k = 0; k < clientCount; k++ )
       
   391                 {
       
   392                 resIndex = GetTrusterResId( iClientUids[k] );
       
   393                 if ( resIndex != KErrNotFound )
       
   394                     {
       
   395                     InsertItemToTrustListL(
       
   396                         resIndex, iClientUids[k], *entry, itemArray, position );
       
   397                     position++;
       
   398                     }
       
   399                 }
       
   400             }
       
   401         }
       
   402     else
       
   403         {
       
   404         return;
       
   405         }
       
   406 
       
   407     iListBox->HandleItemAdditionL();
       
   408     CERTMANUILOGGER_LEAVEFN( " CCertManUIContainerTrust::UpdateListBoxL" );
       
   409     }
       
   410 
       
   411 // ---------------------------------------------------------------------------
       
   412 // CCertManUIContainerTrust::GetTrusterResId( TUid aTrusterUid )
       
   413 // ---------------------------------------------------------------------------
       
   414 //
       
   415 TInt CCertManUIContainerTrust::GetTrusterResId( TUid aTrusterUid )
       
   416     {
       
   417     TInt resIndex = 0;
       
   418     if ( aTrusterUid == KCertManUIViewTrustApplicationControllerId )
       
   419         {
       
   420         resIndex = KTrustSettingsResourceIndexAppCtrl;
       
   421         }
       
   422     else if ( aTrusterUid == KCertManUIViewTrustMailAndImageConnId )
       
   423         {
       
   424         resIndex = KTrustSettingsResourceIndexMailAndImageConn;
       
   425         }
       
   426     else if ( aTrusterUid == KCertManUIViewTrustJavaInstallingId )
       
   427         {
       
   428         resIndex = KTrustSettingsResourceIndexJavaInstall;
       
   429         }
       
   430     else if ( aTrusterUid == KCertManUIViewOCSPCheckInstallingId )
       
   431         {
       
   432         resIndex = KTrustSettingsResourceIndexOCSPCheck;
       
   433         }
       
   434     else if ( aTrusterUid == KCertManUIViewTrustVPNId )
       
   435         {
       
   436         resIndex = KTrustSettingsResourceIndexVPN;
       
   437         }
       
   438     else
       
   439         {
       
   440         resIndex = KErrNotFound;
       
   441         }
       
   442 
       
   443     return resIndex;
       
   444     }
       
   445 
       
   446 
       
   447 // ---------------------------------------------------------------------------
       
   448 // CCertManUIContainerTrust::InsertItemToTrustListL(const TInt aIndex,
       
   449 //                                              const TUid aId,
       
   450 //                                              CCTCertInfo& aEntry,
       
   451 //                                              CDesCArray* aItemArray,
       
   452 //                                              TInt aPosition)
       
   453 // This is helper function for UpdateListBoxL. Inserts trustsetting item to
       
   454 // listbox.
       
   455 // ---------------------------------------------------------------------------
       
   456 //
       
   457 void CCertManUIContainerTrust::InsertItemToTrustListL(
       
   458     const TInt aIndex, const TUid aId,
       
   459     CCTCertInfo& aEntry, CDesCArray* aItemArray,
       
   460     TInt aPosition )
       
   461     {
       
   462     TBuf<KMaxLengthTextSettListOneTwo> item;
       
   463     TBool trustState = EFalse;
       
   464 
       
   465     item = (*iTrustedClients)[ aIndex ];
       
   466     trustState = CheckCertificateClientTrustL( aId, aEntry );
       
   467     if ( trustState )
       
   468         {
       
   469         // item gets its beginning and end
       
   470         // from the resources using indexes
       
   471         item += (*iTrustValues)
       
   472                   [ KTrustSettingsResourceIndexValueYes ];
       
   473         }
       
   474     else
       
   475         {
       
   476         item += (*iTrustValues)
       
   477                   [ KTrustSettingsResourceIndexValueNo ];
       
   478         }
       
   479     aItemArray->InsertL( aPosition, item );
       
   480     }
       
   481 
       
   482 // ---------------------------------------------------------------------------
       
   483 // CCertManUIContainerTrust::CheckCertificateClientTrustL(const TUid aClientTUid,
       
   484 // CCTCertInfo& aEntry) const
       
   485 // Checks if a certificate trusts a client
       
   486 // * Certificate format == ECrX509Certificate ECrX968Certificate ECrCertificateURL
       
   487 // are not supported if certificate location == ECrCertLocationWIMCard
       
   488 // * Certificate format == ECrX968Certificate ECrCertificateURL are not supported
       
   489 // if certificate location == ECrCertLocationCertMan
       
   490 // * Certificate location == ECrCertLocationWIMURL ECrCertLocationPhoneMemory
       
   491 // ECrCertLocationPhoneMemoryURL are not supported
       
   492 // ---------------------------------------------------------------------------
       
   493 //
       
   494 TBool CCertManUIContainerTrust::CheckCertificateClientTrustL(
       
   495     const TUid aClientTUid, CCTCertInfo& aEntry ) const
       
   496     {
       
   497     CERTMANUILOGGER_ENTERFN( " CCertManUIContainerTrust::CheckCertificateClientTrust" );
       
   498 
       
   499     TBool trustSettingTrusted = EFalse;
       
   500     TCertificateFormat format = aEntry.CertificateFormat();
       
   501 
       
   502     if ( format == EX509Certificate )
       
   503         {
       
   504 
       
   505         RArray<TUid> trusterUids;
       
   506         CleanupClosePushL( trusterUids );
       
   507 
       
   508         //Owned by iKeeper.
       
   509         CUnifiedCertStore*& store = iKeeper.CertManager();
       
   510         // Get trusting applications' Uids for the one selected
       
   511         // certificate entry
       
   512         iKeeper.iWrapper->GetApplicationsL( store, aEntry, trusterUids );
       
   513 
       
   514 
       
   515         // get the number of trusting applications for one
       
   516         // selected certificate entry
       
   517         TInt trusterCount = trusterUids.Count();
       
   518         // in this loop, for every trusting application in one
       
   519         // selected certificate entry
       
   520         for ( TInt i = 0; i < trusterCount && !trustSettingTrusted; i++ )
       
   521             {
       
   522             // put the trusting application's Uid to TUid truster
       
   523             if ( aClientTUid == trusterUids[i] )
       
   524                 {
       
   525                 trustSettingTrusted = ETrue;
       
   526                 }
       
   527             }
       
   528         CleanupStack::PopAndDestroy();  // close trusterUids
       
   529         }
       
   530 
       
   531     CERTMANUILOGGER_LEAVEFN( " CCertManUIContainerTrust::CheckCertificateClientTrust" );
       
   532 
       
   533     return trustSettingTrusted;
       
   534     }
       
   535 
       
   536 // ---------------------------------------------------------------------------
       
   537 // CCertManUIContainerTrust::SetEmptyListL(CEikListBox* aListBox)
       
   538 // Sets empty list for listbox.
       
   539 // ---------------------------------------------------------------------------
       
   540 //
       
   541 void CCertManUIContainerTrust::SetEmptyListL( CEikListBox* aListBox )
       
   542     {
       
   543     CERTMANUILOGGER_ENTERFN( " CCertManUIContainerTrust::SetEmptyListL" );
       
   544 
       
   545     // Sets empty list.
       
   546     HBufC* emptyListText = iCoeEnv->AllocReadResourceLC(
       
   547         R_TEXT_RESOURCE_VIEW_TRUST_SETTINGS_EMPTY_LIST );
       
   548     aListBox->View()->SetListEmptyTextL( *emptyListText );
       
   549     CleanupStack::PopAndDestroy();  // emptyListText
       
   550 
       
   551     CERTMANUILOGGER_LEAVEFN( " CCertManUIContainerTrust::SetEmptyListL" );
       
   552     }
       
   553 
       
   554 // ---------------------------------------------------------
       
   555 // CCertManUIContainerTrust::UpdateTrustListboxItemL(CCrCertEntry& aEntry,
       
   556 //                                              TInt aCurrentTruster)
       
   557 // Updates the Trust Settings Listbox item value
       
   558 // Can be called only for those certificates that are
       
   559 // located in ECrCertLocationCertMan !!!
       
   560 // Cannot be called for certificates located in ECrCertLocationWIMCard,
       
   561 //                        ECrCertLocationWIMURL,
       
   562 //                        ECrCertLocationPhoneMemory
       
   563 //                        ECrCertLocationPhoneMemoryURL
       
   564 // Certificate formats ECrX968Certificate ECrCertificateURL
       
   565 // are not visible in the Trust View
       
   566 // ---------------------------------------------------------
       
   567 //
       
   568 void CCertManUIContainerTrust::UpdateTrustListboxItemL(CCTCertInfo& aEntry,
       
   569                                                        TInt aCurrentTruster)
       
   570     {
       
   571     CERTMANUILOGGER_ENTERFN( " CCertManUIContainerTrust::UpdateTrustListboxItemL" );
       
   572 
       
   573     MDesCArray* itemList = iListBox->Model()->ItemTextArray();
       
   574     CDesCArray* itemArray = STATIC_CAST( CDesCArray*, itemList );
       
   575     TCertificateFormat format = aEntry.CertificateFormat();
       
   576     TUid id = KCertManUINullId;
       
   577 
       
   578     TInt poppableItems = 0;
       
   579 
       
   580     TInt index = 0;
       
   581 
       
   582     if ( format == EX509Certificate )
       
   583         {
       
   584         id = iClientUids[ aCurrentTruster ];
       
   585         index = aCurrentTruster;
       
   586         }
       
   587 
       
   588     if ( id != KCertManUINullId )
       
   589         {
       
   590         TBuf<KMaxLengthTextSettListOneTwo> item;
       
   591 
       
   592         if ( id == KCertManUIViewTrustApplicationControllerId )
       
   593             {
       
   594             item = (*iTrustedClients)[ KTrustSettingsResourceIndexAppCtrl ];
       
   595             }
       
   596         else if ( id == KCertManUIViewTrustMailAndImageConnId )
       
   597             {
       
   598             item =
       
   599              (*iTrustedClients)[ KTrustSettingsResourceIndexMailAndImageConn ];
       
   600             }
       
   601         else if ( id == KCertManUIViewTrustJavaInstallingId )
       
   602             {
       
   603             item =
       
   604              (*iTrustedClients)[ KTrustSettingsResourceIndexJavaInstall ];
       
   605             }
       
   606         else if ( id == KCertManUIViewOCSPCheckInstallingId )
       
   607             {
       
   608             item =
       
   609              (*iTrustedClients)[ KTrustSettingsResourceIndexOCSPCheck ];
       
   610             }
       
   611         else if ( id == KCertManUIViewTrustVPNId )
       
   612             {
       
   613             item =
       
   614              (*iTrustedClients)[ KTrustSettingsResourceIndexVPN ];
       
   615             }
       
   616         else
       
   617             {
       
   618             if ( iApps.Count() > 0 )
       
   619                 {
       
   620                 const TName& name = iApps[index].Name();
       
   621                 TInt fieldLength = name.Length();
       
   622                 TBuf<KMaxLengthTextSettListOneTwo> item2;
       
   623                 if ( fieldLength >= KMaxLengthTextSettListOne )
       
   624                     {
       
   625                     item2 = name.Mid( 0, KMaxLengthTextSettListOne );
       
   626                     }
       
   627                 else
       
   628                     {
       
   629                     item2 = name;
       
   630                     }
       
   631                 item.Format( KCertManUIFormatDescriptorTrustSettings, &item2 );
       
   632                 }
       
   633             }
       
   634 
       
   635         if ( item.Length() )
       
   636             {
       
   637             if ( CheckCertificateClientTrustL(id, aEntry) )
       
   638                 {
       
   639                 item += (*iTrustValues)[ KTrustSettingsResourceIndexValueYes ];
       
   640                 }
       
   641             else
       
   642                 {
       
   643                 item += (*iTrustValues)[ KTrustSettingsResourceIndexValueNo ];
       
   644                 }
       
   645             // need to Delete first the old Yes/No entry
       
   646             itemArray->Delete( aCurrentTruster );
       
   647             itemArray->InsertL( aCurrentTruster, item );
       
   648             }
       
   649         }
       
   650 
       
   651     CleanupStack::PopAndDestroy( poppableItems );
       
   652 
       
   653     iListBox->HandleItemAdditionL();
       
   654 
       
   655     CERTMANUILOGGER_LEAVEFN( " CCertManUIContainerTrust::UpdateTrustListboxItemL" );
       
   656     }
       
   657 
       
   658 // ---------------------------------------------------------------------------
       
   659 // CCertManUIContainerTrust::ShowTrustChangeSettingPageL(const TUid aClientUid,
       
   660 //                            TDesC& aClientName,
       
   661 //                            CCTCertInfo& aEntry)
       
   662 // Puts correct client names and yes/no state to settings page
       
   663 // Sets title text to a setting page
       
   664 // ---------------------------------------------------------------------------
       
   665 //
       
   666 void CCertManUIContainerTrust::ShowTrustChangeSettingPageL(
       
   667     const TUid aClientUid, TDesC& aClientName, CCTCertInfo& aEntry )
       
   668     {
       
   669     CERTMANUILOGGER_ENTERFN( " CCertManUIContainerTrust::ShowTrustChangeSettingPageL" );
       
   670 
       
   671     TBool trustState = CheckCertificateClientTrustL( aClientUid, aEntry );
       
   672     TInt oldTrustStatus = 1; // Trust set to No value
       
   673     if ( trustState )
       
   674         {
       
   675         oldTrustStatus = 0; // Trust set to Yes value
       
   676         }
       
   677     TInt newTrustStatus = oldTrustStatus;
       
   678     CDesCArrayFlat* items = iCoeEnv->ReadDesC16ArrayResourceL(
       
   679             R_CERTMANUI_VIEW_TRUST_YES_NO_SETTING_PAGE_LBX );
       
   680     CleanupStack::PushL( items );
       
   681 
       
   682     CAknRadioButtonSettingPage* dlg = new(ELeave) CAknRadioButtonSettingPage(
       
   683             R_CERTMANUI_VIEW_TRUST_YES_NO_SETTING_PAGE, newTrustStatus, items );
       
   684 
       
   685     dlg->SetSettingTextL( aClientName );
       
   686     dlg->ExecuteLD( CAknSettingPage::EUpdateWhenChanged );
       
   687     CleanupStack::PopAndDestroy( items );
       
   688 
       
   689     if ( newTrustStatus != oldTrustStatus )
       
   690         {
       
   691         TInt currentTruster = iListBox->CurrentItemIndex();
       
   692         ChangeTrustValueL( aEntry, aClientUid );
       
   693         UpdateTrustListboxItemL( aEntry, currentTruster );
       
   694         }
       
   695 
       
   696     CERTMANUILOGGER_LEAVEFN( " CCertManUIContainerTrust::ShowTrustChangeSettingPageL" );
       
   697     }
       
   698 
       
   699 // ---------------------------------------------------------------------------
       
   700 // CCertManUIContainerTrust::PopupTrustChangeSettingPageL(
       
   701 //      TInt aCertificateIndex)
       
   702 // Finds out which client was focused in Trust Settings view and calls
       
   703 // ShowTrustChangeSettingPageL This is accessed only by X509S
       
   704 // certificates, located in CertMan and having one or more clients
       
   705 // Must be public so that viewTrust can access
       
   706 // ---------------------------------------------------------------------------
       
   707 //
       
   708 void CCertManUIContainerTrust::PopupTrustChangeSettingPageL(
       
   709     TInt aCertificateIndex )
       
   710     {
       
   711     CERTMANUILOGGER_ENTERFN( " CCertManUIContainerTrust::PopupTrustChangeSettingPageL" );
       
   712 
       
   713     // Use certificate index from previous view
       
   714     CCTCertInfo* entry =
       
   715         iKeeper.iCALabelEntries[ aCertificateIndex ]->iCAEntry;
       
   716 
       
   717     // if the certificate is read-only, trust settings cannot be changed
       
   718     if( !entry->IsDeletable() )
       
   719     	{
       
   720         CERTMANUILOGGER_LEAVEFN( "- PopupTrustChangeSettingPageL - read-only" );
       
   721     	return;
       
   722     	}
       
   723     
       
   724     TUid id = KCertManUINullId;
       
   725     TInt poppableItems = 0;
       
   726 
       
   727     TBuf<KMaxLengthTextSettListOne> clientName;
       
   728 
       
   729     // get position of the focus in the Trust Settings view
       
   730     TInt currentPosition = iListBox->CurrentItemIndex();
       
   731     id = iClientUids[ currentPosition ];
       
   732 
       
   733     if ( id != KCertManUINullId )
       
   734         {
       
   735         // Native installation
       
   736         if ( id == KCertManUIViewTrustApplicationControllerId )
       
   737             {
       
   738             clientName =
       
   739                     (*iTrustedClients)[ KTrustSettingsResourceIndexAppCtrl ];
       
   740             }
       
   741         // TLS
       
   742         else if ( id == KCertManUIViewTrustMailAndImageConnId )
       
   743             {
       
   744             clientName =
       
   745                   (*iTrustedClients)[
       
   746                   KTrustSettingsResourceIndexMailAndImageConn ];
       
   747             }
       
   748         // Midlet installation
       
   749         else if ( id == KCertManUIViewTrustJavaInstallingId )
       
   750             {
       
   751             clientName =
       
   752                   (*iTrustedClients)[
       
   753                   KTrustSettingsResourceIndexJavaInstall ];
       
   754             }
       
   755         // OCSP
       
   756         else if ( id == KCertManUIViewOCSPCheckInstallingId )
       
   757             {
       
   758             clientName =
       
   759                   (*iTrustedClients)[
       
   760                   KTrustSettingsResourceIndexOCSPCheck ];
       
   761             }
       
   762         // VPN
       
   763         else if ( id == KCertManUIViewTrustVPNId )
       
   764             {
       
   765             clientName =
       
   766                   (*iTrustedClients)[
       
   767                   KTrustSettingsResourceIndexVPN ];
       
   768             }
       
   769         else
       
   770             {
       
   771             if ( iApps.Count() > 0 )
       
   772                 {
       
   773                 const TName& name = iApps[currentPosition].Name();
       
   774                 TInt fieldLength = name.Length();
       
   775                 if ( fieldLength >= KMaxLengthTextSettListOne )
       
   776                     {
       
   777                     clientName = name.Mid(0, KMaxLengthTextSettListOne);
       
   778                     }
       
   779                 else
       
   780                     {
       
   781                     clientName = name;
       
   782                     }
       
   783                 }
       
   784             }
       
   785         }
       
   786 
       
   787     if ( id != KCertManUINullId )
       
   788         {
       
   789         clientName.TrimLeft();
       
   790         clientName.TrimRight();
       
   791         ShowTrustChangeSettingPageL( id, clientName, *entry );
       
   792         }
       
   793 
       
   794     CleanupStack::PopAndDestroy( poppableItems );  // clients
       
   795 
       
   796     CERTMANUILOGGER_LEAVEFN( " CCertManUIContainerTrust::PopupTrustChangeSettingPageL" );
       
   797     }
       
   798 
       
   799 // ---------------------------------------------------------
       
   800 // CCertManUIContainerTrust::ChangeTrustValueL(CCTCertInfo& aEntry)
       
   801 // Changes the Trust state of client in the CertManAPI
       
   802 // ChangeTrustValueL is called only for certificates located
       
   803 // in certman.
       
   804 // ---------------------------------------------------------
       
   805 //
       
   806 void CCertManUIContainerTrust::ChangeTrustValueL(
       
   807     CCTCertInfo& aEntry, const TUid aClientUid )
       
   808     {
       
   809     CERTMANUILOGGER_ENTERFN( " CCertManUIContainerTrust::ChangeTrustValueL" );
       
   810 
       
   811     RArray<TUid> trusterUids;
       
   812     CleanupClosePushL( trusterUids );
       
   813 
       
   814     iKeeper.iWrapper->GetApplicationsL(
       
   815         iKeeper.CertManager(), aEntry, trusterUids );
       
   816 
       
   817     RArray<TUid> newUids;
       
   818     CleanupClosePushL( newUids );
       
   819 
       
   820     // Go through all applications and if aClientId does not exist, add it and
       
   821     // update certificates data.
       
   822     TBool add = ETrue;
       
   823     for ( TInt i = 0; i < trusterUids.Count(); i++ )
       
   824         {
       
   825         if ( aClientUid == trusterUids[i] )
       
   826             {
       
   827             add = EFalse;
       
   828             }
       
   829         else
       
   830             {
       
   831             newUids.Append( trusterUids[i] );
       
   832             }
       
   833         }
       
   834 
       
   835     if ( add )
       
   836         {
       
   837         newUids.Append( aClientUid );
       
   838         }
       
   839 
       
   840     iKeeper.iWrapper->SetApplicabilityL(
       
   841         iKeeper.CertManager(), aEntry, newUids );
       
   842 
       
   843     CleanupStack::PopAndDestroy(2);  // trusterUids, newUids
       
   844 
       
   845     CERTMANUILOGGER_LEAVEFN( " CCertManUIContainerTrust::ChangeTrustValueL" );
       
   846     }
       
   847 
       
   848 // ---------------------------------------------------------
       
   849 // CCertManUIContainerTrust::HandleResourceChange
       
   850 //
       
   851 // ---------------------------------------------------------
       
   852 //
       
   853 void CCertManUIContainerTrust::HandleResourceChange(TInt aType)
       
   854     {
       
   855     CCoeControl::HandleResourceChange(aType);
       
   856 
       
   857     if (aType == KEikDynamicLayoutVariantSwitch)
       
   858         {
       
   859         TRect mainPaneRect;
       
   860         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect);
       
   861         SetRect(mainPaneRect);
       
   862         DrawNow();
       
   863         }
       
   864     }
       
   865 
       
   866 // ---------------------------------------------------------
       
   867 // CCertManUIContainerTrust::GetHelpContext
       
   868 // This function is called when Help application is launched.
       
   869 // (other items were commented in a header).
       
   870 // ---------------------------------------------------------
       
   871 //
       
   872 void CCertManUIContainerTrust::GetHelpContext( TCoeHelpContext& aContext ) const
       
   873     {
       
   874     aContext.iMajor = KUidCM;
       
   875     aContext.iContext = KCM_HLP_TRUST_SETTINGS;
       
   876     }
       
   877 
       
   878 // End of File
       
   879