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