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