pkiutilities/SecModUI/src/SecModUIViewAccess.cpp
changeset 0 164170e6151a
child 5 3b17fc5c9564
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2005-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 the CSecModUIViewAccess class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include  "SecModUIContainerAccess.h"
       
    21 #include  "SecModUIViewAccess.h" 
       
    22 #include  "SecModUIModel.h"
       
    23 #include  "SecModUISyncWrapper.h"
       
    24 #include  "secmodui.hrh"
       
    25 #include  <SecModUI.rsg>
       
    26 #include  <aknViewAppUi.h>
       
    27 #include  <avkon.hrh>
       
    28 #include  <aknlists.h>
       
    29 #include  <eikmenup.h>
       
    30 #include  <featmgr.h>
       
    31 
       
    32 // CONSTANTS
       
    33 
       
    34 // ================= MEMBER FUNCTIONS =======================
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CSecModUIViewAccess::CSecModUIViewAccess
       
    38 // C++ default constructor can NOT contain any code, that
       
    39 // might leave.
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CSecModUIViewAccess::CSecModUIViewAccess(CSecModUIModel& aModel):
       
    43     CSecModUIViewBase(aModel)
       
    44     {
       
    45     }
       
    46 
       
    47 // ---------------------------------------------------------
       
    48 // CSecModUIViewAccess::ConstructL(const TRect& aRect)
       
    49 // EPOC two-phased constructor
       
    50 // ---------------------------------------------------------
       
    51 //
       
    52 void CSecModUIViewAccess::ConstructL()
       
    53     {
       
    54     BaseConstructL( R_SECMODUI_VIEW_ACCESS );
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------
       
    58 // CSecModUIViewAccess::~CSecModUIViewAccess()
       
    59 // destructor
       
    60 // ---------------------------------------------------------
       
    61 //
       
    62 CSecModUIViewAccess::~CSecModUIViewAccess()
       
    63     {
       
    64     
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------
       
    68 // CSecModUIViewCode::NewLC
       
    69 // Two-phased constructor.
       
    70 // ---------------------------------------------------------
       
    71 //
       
    72 CSecModUIViewAccess* CSecModUIViewAccess::NewLC(CSecModUIModel& aModel)
       
    73     {
       
    74     CSecModUIViewAccess* self = new (ELeave) CSecModUIViewAccess(aModel);
       
    75     CleanupStack::PushL(self);
       
    76     self->ConstructL();
       
    77     return self;
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------
       
    81 // TUid CSecModUIViewAccess::Id()
       
    82 //
       
    83 // ---------------------------------------------------------
       
    84 //
       
    85 TUid CSecModUIViewAccess::Id() const
       
    86     {
       
    87     return KSecModUIViewAccessId;
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------
       
    91 // void CSecModUIViewCode::CreateContainerL()
       
    92 // Creates container
       
    93 // ---------------------------------------------------------
       
    94 //
       
    95 void CSecModUIViewAccess::CreateContainerL()
       
    96     {
       
    97     iContainer = new (ELeave) CSecModUIContainerAccess(iModel, this);
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------
       
   101 // CSecModUIViewAccess::AddNavipaneLabelL()
       
   102 // Default implementation is empty
       
   103 // ---------------------------------------------------------
       
   104 //
       
   105 void CSecModUIViewAccess::AddNaviPaneLabelL()
       
   106     { 
       
   107     DoAddNaviPaneL(R_NAVIPANE_ACCESS_TEXT);   
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------
       
   111 // CSecModUIViewAccess::HandleCommandL(TInt aCommand)
       
   112 // takes care of view command handling
       
   113 // ---------------------------------------------------------
       
   114 //
       
   115 void CSecModUIViewAccess::HandleCommandL(TInt aCommand)
       
   116     {
       
   117     if (iModel.Wrapper().IsActive())
       
   118         {
       
   119         return;
       
   120         }   
       
   121     switch ( aCommand )
       
   122         {
       
   123         case ESecModUICmdChange:
       
   124             {
       
   125             HandleChangeL();            
       
   126             break;
       
   127             }
       
   128         case ESecModUICmdUnblock:
       
   129             {
       
   130             iModel.UnblockPinL(KPinGIndex);
       
   131             UpdateListBoxItemL(EIndexCodeStatus);
       
   132             UpdateListBoxItemL(EIndexCodeRequest);
       
   133             UpdateCbaL();
       
   134             break;
       
   135             }
       
   136         case ESecModUICmdClose:
       
   137             {
       
   138             iModel.CloseAuthObjL(KPinGIndex);
       
   139             UpdateListBoxItemL(EIndexCodeStatus);
       
   140             UpdateCbaL();
       
   141             break;
       
   142             }
       
   143         case EAknSoftkeyChange:
       
   144             {
       
   145             HandleChangeL();	
       
   146             break;	
       
   147             }
       
   148         case EAknSoftkeyClose:
       
   149             {
       
   150             iModel.CloseAuthObjL(KPinGIndex);
       
   151             UpdateListBoxItemL(EIndexCodeStatus);
       
   152             UpdateCbaL();
       
   153             break;	
       
   154             }
       
   155             
       
   156         case EAknSoftkeyUnlock:
       
   157             {
       
   158             iModel.UnblockPinL(KPinGIndex);
       
   159             UpdateListBoxItemL(EIndexCodeStatus);
       
   160             UpdateListBoxItemL(EIndexCodeRequest);
       
   161             UpdateCbaL();
       
   162             break;	
       
   163             }
       
   164         default:
       
   165             {
       
   166             CSecModUIViewBase::HandleCommandL( aCommand );
       
   167             break;
       
   168             }
       
   169         }
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------
       
   173 // CSecModUIViewAccess::HandleChangeL()
       
   174 // takes care of Change command handling
       
   175 // ---------------------------------------------------------
       
   176 //
       
   177 void CSecModUIViewAccess::HandleChangeL()
       
   178     {
       
   179     TInt currentItem = iContainer->ListBox().CurrentItemIndex();
       
   180     
       
   181     switch (currentItem)
       
   182         {
       
   183         case EIndexCodeLabel:
       
   184             {
       
   185             iModel.ChangeOrUnblockPinL(KPinGIndex);
       
   186             UpdateListBoxItemL(EIndexCodeStatus);
       
   187             UpdateCbaL();
       
   188             break;
       
   189             }
       
   190         case EIndexCodeRequest:
       
   191             {
       
   192             if (KErrCancel != iModel.ChangeCodeRequestL(KPinGIndex))
       
   193                 {
       
   194                 UpdateListBoxItemL(EIndexCodeRequest);
       
   195                 UpdateListBoxItemL(EIndexCodeStatus);
       
   196                 UpdateCbaL();
       
   197                 }
       
   198             break;
       
   199             }
       
   200         default:
       
   201             {
       
   202             break;
       
   203             }                
       
   204         }
       
   205     }
       
   206 // ---------------------------------------------------------
       
   207 // CSecModUIViewAccess::HandleForegroundEventL()
       
   208 // ---------------------------------------------------------
       
   209 //
       
   210 void CSecModUIViewAccess::HandleForegroundEventL(TBool aForeground)
       
   211     {
       
   212 	if( aForeground && !iModel.Wrapper().IsActive() )
       
   213 	    {
       
   214 	    UpdateListBoxItemL(EIndexCodeRequest);
       
   215         UpdateListBoxItemL(EIndexCodeStatus);
       
   216         UpdateCbaL();	
       
   217 	    }
       
   218     }
       
   219 
       
   220 
       
   221 // ---------------------------------------------------------
       
   222 // CSecModUIViewAccess::UpdateListBoxItemL(TInt aIndex)
       
   223 // Updates listbox item
       
   224 // ---------------------------------------------------------
       
   225 //
       
   226 void CSecModUIViewAccess::UpdateListBoxItemL(TInt aIndex)
       
   227     {
       
   228     TBuf<KMaxSettItemSize> item; 
       
   229         CDesCArray* itemArray = STATIC_CAST(CDesCArray*, 
       
   230             iContainer->ListBox().Model()->ItemTextArray());
       
   231     switch(aIndex)
       
   232         {
       
   233         case EIndexCodeRequest:
       
   234             {
       
   235             iModel.PINRequestItemL(KPinGIndex, item);
       
   236             break;
       
   237             }
       
   238         case EIndexCodeStatus:
       
   239             {
       
   240             iModel.PINStatusItemL(KPinGIndex, item, EFalse);
       
   241             break;
       
   242             }
       
   243         default: 
       
   244             {
       
   245             return;
       
   246             }
       
   247         }
       
   248     itemArray->Delete(aIndex);    
       
   249     itemArray->InsertL(aIndex, item);
       
   250     iContainer->ListBox().HandleItemAdditionL();
       
   251     iContainer->DrawNow();
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------
       
   255 // CSecModUIViewAccess::UpdateCbaL()
       
   256 // Updates Cba area
       
   257 // ---------------------------------------------------------
       
   258 //    
       
   259 void CSecModUIViewAccess::UpdateCbaL()
       
   260     {
       
   261     TInt currentItem = iContainer->ListBox().CurrentItemIndex();
       
   262     switch (currentItem)
       
   263             {
       
   264             case EIndexCodeLabel:
       
   265                 {
       
   266                  if( iModel.PinChangeable(KPinGIndex) )
       
   267                      {
       
   268                      SetCbaL(R_SECMODUI_SOFTKEYS_OPTIONS_BACK_CHANGE);
       
   269                      }   
       
   270                  else
       
   271                      {
       
   272                      if( !iModel.PinUnblockable(KPinGIndex) )
       
   273                          {
       
   274                          SetCbaL(R_SECMODUI_SOFTKEYS_OPTIONS_BACK);
       
   275                          } 
       
   276                      else
       
   277                          {
       
   278                          SetCbaL(R_SECMODUI_SOFTKEYS_OPTIONS_BACK_UNBLOCK);	
       
   279                          }     
       
   280                      }    	    
       
   281                 break;
       
   282                 }
       
   283             case EIndexCodeRequest:
       
   284                 {
       
   285                 if( iModel.PinRequestChangeable(KPinGIndex) )
       
   286                      {
       
   287                      SetCbaL(R_SECMODUI_SOFTKEYS_OPTIONS_BACK_CHANGE);
       
   288                      }   
       
   289                  else
       
   290                      {
       
   291                      if( !iModel.PinUnblockable(KPinGIndex) )
       
   292                          {
       
   293                          SetCbaL(R_SECMODUI_SOFTKEYS_OPTIONS_BACK);
       
   294                          } 
       
   295                      else
       
   296                          {
       
   297                          SetCbaL(R_SECMODUI_SOFTKEYS_OPTIONS_BACK_UNBLOCK);	
       
   298                          }     
       
   299                      }     
       
   300                 break;
       
   301                 }
       
   302             case EIndexCodeStatus:
       
   303                 {
       
   304                 if( !iModel.PinChangeable(KPinGIndex) && iModel.PinUnblockable(KPinGIndex))
       
   305                     {
       
   306                     SetCbaL(R_SECMODUI_SOFTKEYS_OPTIONS_BACK_UNBLOCK);	
       
   307                     }     
       
   308                 else if(iModel.PinOpen(KPinGIndex))  
       
   309                     {
       
   310                 	SetCbaL(R_SECMODUI_SOFTKEYS_OPTIONS_BACK_CLOSE);
       
   311                     }
       
   312                 else
       
   313                     {
       
   314                     SetCbaL(R_SECMODUI_SOFTKEYS_OPTIONS_BACK);	
       
   315                     }    
       
   316                 
       
   317                 break;
       
   318                 }
       
   319             default:
       
   320                 {
       
   321                 break;
       
   322                 }
       
   323             }    	
       
   324     }
       
   325 
       
   326 
       
   327 // ---------------------------------------------------------
       
   328 // CSecModUIViewAccess::SetCbaL( TInt aCbaResourceId )
       
   329 // Sets Cba area
       
   330 // ---------------------------------------------------------
       
   331 //  
       
   332 void CSecModUIViewAccess::SetCbaL( TInt aCbaResourceId )
       
   333     {
       
   334 	CEikButtonGroupContainer*  cba = Cba();
       
   335     cba->SetCommandSetL(aCbaResourceId);
       
   336     cba->DrawNow();
       
   337     }
       
   338     
       
   339     
       
   340 // ---------------------------------------------------------
       
   341 // TUid CSecModUIViewAccess::DynInitMenuPaneL(
       
   342 //      TInt aResourceId, CEikMenuPane* aMenuPane)
       
   343 //
       
   344 // ---------------------------------------------------------
       
   345 //
       
   346 void CSecModUIViewAccess::DynInitMenuPaneL(
       
   347     TInt aResourceId, 
       
   348     CEikMenuPane* aMenuPane)
       
   349     {
       
   350     if( R_SECMODUI_VIEW_ACCESS_MENU == aResourceId )
       
   351         {        
       
   352         if( aResourceId == !FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   353             {
       
   354             aMenuPane->DeleteMenuItem( EAknCmdHelp ); //remove help
       
   355             }     
       
   356 
       
   357         TInt currentItem = iContainer->ListBox().CurrentItemIndex();
       
   358         if( currentItem == EIndexCodeLabel )
       
   359             {
       
   360             if( !iModel.PinChangeable(KPinGIndex) )
       
   361                 {
       
   362                 aMenuPane->SetItemDimmed( ESecModUICmdChange, ETrue );
       
   363                 }
       
   364             }
       
   365         else if( currentItem == EIndexCodeRequest )
       
   366             {
       
   367             if( !iModel.PinRequestChangeable(KPinGIndex) )
       
   368                 {
       
   369                 aMenuPane->SetItemDimmed( ESecModUICmdChange, ETrue );
       
   370                 }
       
   371             }
       
   372         else // it is EIndexCodeStatus
       
   373             {
       
   374             aMenuPane->SetItemDimmed( ESecModUICmdChange, ETrue );
       
   375             }
       
   376 
       
   377         if( !iModel.PinUnblockable(KPinGIndex) )
       
   378             {
       
   379             aMenuPane->SetItemDimmed( ESecModUICmdUnblock, ETrue );
       
   380             }
       
   381         if( !iModel.PinOpen(KPinGIndex) )
       
   382             {
       
   383             aMenuPane->SetItemDimmed( ESecModUICmdClose, ETrue );
       
   384             }
       
   385         }
       
   386     }
       
   387 
       
   388 // ---------------------------------------------------------
       
   389 // CSecModUIViewAccess::HandleEnterKeyL(TInt aIndex)
       
   390 //     
       
   391 // ---------------------------------------------------------
       
   392 //   
       
   393 void CSecModUIViewAccess::HandleEnterKeyL(TInt aIndex)
       
   394     {
       
   395     switch(aIndex)
       
   396         {        
       
   397         case EIndexCodeLabel:
       
   398             {
       
   399             HandleChangeL();
       
   400             break;
       
   401             }
       
   402         case EIndexCodeRequest:
       
   403             {
       
   404             HandleChangeL();
       
   405             break;
       
   406             }
       
   407         case EIndexCodeStatus:
       
   408             {
       
   409             iModel.CloseAuthObjL(KPinGIndex);
       
   410             UpdateListBoxItemL(EIndexCodeStatus);
       
   411             UpdateCbaL();
       
   412             break;
       
   413             }
       
   414         default:
       
   415             {
       
   416             break;
       
   417             }
       
   418         }
       
   419     }
       
   420 
       
   421 // ---------------------------------------------------------
       
   422 // CSecModUIViewAccess::HandleListBoxEventL(
       
   423 //     CEikListBox* aListBox, TListBoxEvent aEventType)
       
   424 // ---------------------------------------------------------
       
   425 //   
       
   426 void CSecModUIViewAccess::HandleListBoxEventL(
       
   427     CEikListBox* aListBox, 
       
   428     TListBoxEvent aEventType)
       
   429     {
       
   430     if(iModel.Wrapper().IsActive())
       
   431         {
       
   432         return;	
       
   433         }
       
   434         
       
   435     TInt index = aListBox->CurrentItemIndex();
       
   436 
       
   437     switch( aEventType )
       
   438 		{
       
   439 		case EEventEnterKeyPressed:
       
   440 		case EEventItemDoubleClicked:
       
   441 		case EEventItemSingleClicked:
       
   442 			{
       
   443 			HandleEnterKeyL(index);
       
   444             break;
       
   445 			}
       
   446         default:
       
   447             {
       
   448 			break;
       
   449             }
       
   450 		}           
       
   451     }
       
   452 
       
   453 
       
   454 // ---------------------------------------------------------
       
   455 // CSecModUIViewAccess::DoDeactivate()
       
   456 // 
       
   457 // ---------------------------------------------------------
       
   458 //
       
   459 void CSecModUIViewAccess::DoActivateL(
       
   460    const TVwsViewId& aPrevViewId,TUid /*aCustomMessageId*/,
       
   461    const TDesC8& /*aCustomMessage*/)
       
   462     {
       
   463   
       
   464     if (KNullUid == iPrevViewId.iViewUid)
       
   465         {
       
   466         iPrevViewId = aPrevViewId;
       
   467         }
       
   468     SetTitlePaneL();
       
   469     AddNaviPaneLabelL();
       
   470                     
       
   471     if (!iContainer)
       
   472         {
       
   473         CreateContainerL();
       
   474         iContainer->SetMopParent(this);
       
   475         iContainer->ConstructL(ClientRect());
       
   476         iContainer->ListBox().SetListBoxObserver(this);
       
   477         AppUi()->AddToStackL(*this, iContainer);
       
   478         }         
       
   479    iContainer->MakeVisible(ETrue);
       
   480    iContainer->SetRect(ClientRect());
       
   481    iContainer->ActivateL();
       
   482    
       
   483    UpdateCbaL();  
       
   484    }
       
   485 
       
   486 // ---------------------------------------------------------
       
   487 // CSecModUIViewAccess::DoDeactivate()
       
   488 // 
       
   489 // ---------------------------------------------------------
       
   490 //
       
   491 void CSecModUIViewAccess::DoDeactivate()
       
   492     {
       
   493     if ( iContainer )
       
   494         {
       
   495         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   496         }
       
   497     
       
   498     delete iContainer;
       
   499     iContainer = NULL;    
       
   500     }    
       
   501     
       
   502 // End of File
       
   503