pkiutilities/SecModUI/src/SecModUIModel.cpp
changeset 0 164170e6151a
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 CSecModUIModel class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "SecModUI.h"
       
    22 #include    "SecModUIModel.h"
       
    23 #include    "SecModUIViewAccess.h"
       
    24 #include    "SecModUIViewCode.h"
       
    25 #include    "SecModUIViewMain.h"
       
    26 #include    "SecModUIViewSignature.h"
       
    27 #include    "SecModUISyncWrapper.h"
       
    28 #include    "SecModUILogger.h"
       
    29 #include    <SecModUI.rsg>
       
    30 #include    <certmanui.rsg>
       
    31 #include    <CTSecDlgs.rsg>
       
    32 #include    <aknViewAppUi.h>
       
    33 #include    <AknUtils.h>
       
    34 #include    <data_caging_path_literals.hrh>
       
    35 #include    <bautils.h>
       
    36 #include    <unifiedkeystore.h>
       
    37 #include    <aknlists.h>
       
    38 #include    <mctauthobject.h>
       
    39 #include    <aknnotewrappers.h>
       
    40 #include    <StringLoader.h>
       
    41 #include    <mctkeystore.h>
       
    42 #include    <akntitle.h>
       
    43 #include    <aknmessagequerydialog.h>
       
    44 #include    <eikenv.h>
       
    45 #include    <securityerr.h>
       
    46 #include    <AknGlobalNote.h>
       
    47 
       
    48 // CONSTANTS
       
    49 _LIT(KResourceFile, "z:SecModUI.rsc");
       
    50 _LIT(KResourceFile2, "z:CertManUI.rsc");
       
    51 _LIT(KResourceFile3, "z:CTsecdlgs.rsc");
       
    52 _LIT(KTab, " \t");
       
    53 _LIT(KDoubleTab, "\t\t");
       
    54 _LIT(KFourAsterisks,"****");
       
    55 _LIT(KEnter, "\n");
       
    56 _LIT(KDoubleEnter, "\n\n");
       
    57 
       
    58 _LIT(KSecModUIPanic, "Security Module UI panic");
       
    59 
       
    60 const TInt KMaxLengthTextDetailsBody = 750;
       
    61 const TInt KMaxLengthItemValue = 100;
       
    62 const TInt KWIMStoreUid ( 0x101F79D9 );
       
    63 const TInt KItemLength (200);
       
    64 
       
    65 // ============================= LOCAL FUNCTIONS ===============================
       
    66 GLDEF_C void Panic(TInt aPanic)
       
    67   {
       
    68   User::Panic(KSecModUIPanic, aPanic);
       
    69   }
       
    70 
       
    71 // ============================ MEMBER FUNCTIONS ===============================
       
    72 #ifndef RD_GS_RENOVATION
       
    73 EXPORT_C MSecModUI* MSecModUI::CreateL()
       
    74     {
       
    75     LOG_CREATE;
       
    76     LOG_ENTERFN("MSecModUI::CreateL()");
       
    77     LOG_LEAVEFN("MSecModUI::CreateL()");
       
    78     return CSecModUIModel::NewL();
       
    79     }
       
    80 #endif
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CSecModUIModel::CSecModUIModel
       
    84 // C++ default constructor can NOT contain any code, that
       
    85 // might leave.
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 CSecModUIModel::CSecModUIModel()
       
    89     {
       
    90   LOG_WRITE( "CSecModUIModel::CSecModUIModel" );
       
    91     }
       
    92 
       
    93 // Destructor
       
    94 CSecModUIModel::~CSecModUIModel()
       
    95     {
       
    96     LOG_ENTERFN("CSecModUIModel::~CSecModUIModel");    
       
    97     delete iWrapper;
       
    98     if ( iResourceFileOffset )
       
    99         {
       
   100     iEikEnv->DeleteResourceFile( iResourceFileOffset );
       
   101         }
       
   102     if ( iResourceFileOffset2 )
       
   103         {
       
   104     iEikEnv->DeleteResourceFile( iResourceFileOffset2 );
       
   105         }
       
   106     if ( iResourceFileOffset3 )
       
   107         {
       
   108     iEikEnv->DeleteResourceFile( iResourceFileOffset3 );
       
   109         }    
       
   110     ResetAndDestroyCTObjects();
       
   111     LOG_LEAVEFN("CSecModUIModel::~CSecModUIModel");
       
   112     LOG_DELETE;
       
   113     }
       
   114 // -----------------------------------------------------------------------------
       
   115 // CSecModUIModel::ResetAndDestroyCTObjects()
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 void CSecModUIModel::ResetAndDestroyCTObjects()
       
   119     {
       
   120     LOG_ENTERFN("CSecModUIModel::ResetAndDestroyCTObjects()");
       
   121 
       
   122     ResetAndDestroyAOs();
       
   123     
       
   124     iAOKeyStores.Reset();
       
   125 
       
   126     delete iUnifiedKeyStore;
       
   127     iUnifiedKeyStore = NULL;
       
   128     iKeyStore = NULL;
       
   129     LOG_LEAVEFN("CSecModUIModel::ResetAndDestroyCTObjects()");
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CSecModUIModel::ResetAndDestroyAOs()
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void CSecModUIModel::ResetAndDestroyAOs()
       
   137     {
       
   138     LOG_ENTERFN("CSecModUIModel::ResetAndDestroyAOs()");
       
   139     if (iAOList)
       
   140         {
       
   141         iAOList->Release();
       
   142         iAOList = NULL;
       
   143         }
       
   144     if (iAOArray.Count() > 0 &&
       
   145         iAOArray[0]->Token().TokenType().Type().iUid == KTokenTypeFileKeystore)
       
   146         {
       
   147         iAOArray.Reset();
       
   148         }
       
   149     else
       
   150         {
       
   151         iAOArray.Close();
       
   152         }
       
   153     LOG_LEAVEFN("CSecModUIModel::ResetAndDestroyAOs()");
       
   154     }
       
   155     
       
   156 // -----------------------------------------------------------------------------
       
   157 // CSecModUIModel::ConstructL()
       
   158 // Symbian 2nd phase constructor can leave.
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 void CSecModUIModel::ConstructL()
       
   162     {
       
   163     LOG_ENTERFN("CSecModUIModel::ConstructL()");
       
   164     iEikEnv = CEikonEnv::Static();
       
   165     AddResourceFileL();
       
   166 
       
   167 #ifndef RD_GS_RENOVATION
       
   168 
       
   169     CSecModUIViewMain* viewMain = CSecModUIViewMain::NewLC(*this);
       
   170     ((CAknViewAppUi*)iEikEnv->EikAppUi())->AddViewL(viewMain);
       
   171     CleanupStack::Pop(viewMain);
       
   172 
       
   173     CSecModUIViewCode* viewCode = CSecModUIViewCode::NewLC(*this);
       
   174     ((CAknViewAppUi*)iEikEnv->EikAppUi())->AddViewL(viewCode);
       
   175     CleanupStack::Pop(viewCode);
       
   176 
       
   177     CSecModUIViewAccess* viewAccess = CSecModUIViewAccess::NewLC(*this);
       
   178     ((CAknViewAppUi*)iEikEnv->EikAppUi())->AddViewL(viewAccess);
       
   179     CleanupStack::Pop(viewAccess);
       
   180 
       
   181     CSecModUIViewSignature* viewSignature = 
       
   182         CSecModUIViewSignature::NewLC(*this);
       
   183     ((CAknViewAppUi*)iEikEnv->EikAppUi())->AddViewL(viewSignature);
       
   184     CleanupStack::Pop(viewSignature);
       
   185 #endif
       
   186     InitializeKeyStoreL();
       
   187     LOG_LEAVEFN("CSecModUIModel::ConstructL()");
       
   188     }
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // CSecModUIModel::NewL()
       
   192 // Two-phased constructor.
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 CSecModUIModel* CSecModUIModel::NewL()
       
   196     {
       
   197     LOG_ENTERFN("CSecModUIModel::NewL()");
       
   198     CSecModUIModel* self = new( ELeave ) CSecModUIModel();
       
   199 
       
   200     CleanupStack::PushL( self );
       
   201     self->ConstructL();
       
   202     CleanupStack::Pop();
       
   203     LOG_LEAVEFN("CSecModUIModel::NewL()");
       
   204     return self;
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // CSecModUIModel::InitializeKeyStoreL()
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 TInt CSecModUIModel::InitializeKeyStoreL()
       
   212     {
       
   213     LOG_ENTERFN("CSecModUIModel::InitializeKeyStoreL()");
       
   214     ResetAndDestroyCTObjects();
       
   215     iUnifiedKeyStore = CUnifiedKeyStore::NewL(iEikEnv->FsSession());
       
   216 
       
   217     if (iWrapper == NULL)
       
   218         {
       
   219         iWrapper = CSecModUISyncWrapper::NewL();
       
   220         }
       
   221 
       
   222     TInt err = iWrapper->Initialize(*iUnifiedKeyStore);
       
   223 
       
   224     ShowErrorNoteL(err);
       
   225     if (KErrNone != err && KErrHardwareNotAvailable != err)
       
   226         {
       
   227         LOG_LEAVEFN("CSecModUIModel::InitializeKeyStoreL()");
       
   228         return err;
       
   229         }
       
   230     TInt keyStoreCount = iUnifiedKeyStore->KeyStoreCount();
       
   231     if (0 >= keyStoreCount)
       
   232         {
       
   233         LOG_LEAVEFN("CSecModUIModel::InitializeKeyStoreL()");
       
   234         return KErrNone;
       
   235         }
       
   236 
       
   237     RMPointerArray<CCTKeyInfo> keyInfos;
       
   238     CleanupClosePushL(keyInfos);
       
   239     TCTKeyAttributeFilter filter;
       
   240     TInt keyInfoCount = 0;
       
   241     filter.iPolicyFilter = TCTKeyAttributeFilter::EAllKeys;
       
   242 
       
   243     for (TInt i = 0; i < keyStoreCount; i++)
       
   244         {
       
   245         err = iWrapper->ListKeys(iUnifiedKeyStore->KeyStore(i), keyInfos, filter);
       
   246         LOG_WRITE_FORMAT( "CSecModUIModel::InitializeKeyStoreL() list err = %d ", err );
       
   247         
       
   248         //If list ok, append the AO, otherwise go next
       
   249         if ( err == KErrNone )
       
   250             {
       
   251              keyInfoCount = keyInfos.Count();
       
   252             for (TInt j = 0; j < keyInfoCount; j++)
       
   253                 {
       
   254                 // Check that keystore has at least one AO.
       
   255                 if (NULL != keyInfos[j]->Protector())
       
   256                     {
       
   257                     // If keystore has AO, add it to the array.
       
   258                     User::LeaveIfError(
       
   259                         iAOKeyStores.Append(&(iUnifiedKeyStore->KeyStore(i))));
       
   260                     break;
       
   261                     }
       
   262                 } 
       
   263             }
       
   264         keyInfos.Close();
       
   265         }
       
   266     CleanupStack::PopAndDestroy(&keyInfos);  //keyInfos
       
   267 
       
   268     LOG_LEAVEFN("CSecModUIModel::InitializeKeyStoreL()");
       
   269     return KErrNone;
       
   270     }
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // CSecModUIModel::AddResourceFileL()
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 void CSecModUIModel::AddResourceFileL()
       
   277   {
       
   278   LOG_ENTERFN("CSecModUIModel::AddResourceFileL()");
       
   279     // Resource file loading
       
   280   RFs& fs = iEikEnv->FsSession();
       
   281 
       
   282   TFileName fileName;
       
   283 
       
   284   TParse parse;
       
   285   // secmodui.rsc
       
   286     parse.Set(KResourceFile, &KDC_RESOURCE_FILES_DIR, NULL);
       
   287 
       
   288   fileName = parse.FullName();
       
   289 
       
   290   BaflUtils::NearestLanguageFile( fs, fileName );
       
   291   iResourceFileOffset = iEikEnv->AddResourceFileL( fileName );
       
   292 
       
   293   // CertManUI.rsc
       
   294   parse.Set(KResourceFile2, &KDC_RESOURCE_FILES_DIR, NULL);
       
   295     fileName = parse.FullName();
       
   296     BaflUtils::NearestLanguageFile( fs, fileName );
       
   297     iResourceFileOffset2 = iEikEnv->AddResourceFileL( fileName );
       
   298 
       
   299   // CTSecDlg.rsc
       
   300   parse.Set(KResourceFile3, &KDC_RESOURCE_FILES_DIR, NULL);
       
   301     fileName = parse.FullName();
       
   302     BaflUtils::NearestLanguageFile( fs, fileName );
       
   303     iResourceFileOffset3 = iEikEnv->AddResourceFileL( fileName );
       
   304 
       
   305   LOG_LEAVEFN("CSecModUIModel::AddResourceFileL()");
       
   306   }
       
   307 
       
   308 // -----------------------------------------------------------------------------
       
   309 // CSecModUIModel::LoadTokenLabelsL(CEikTextListBox& aListBox)
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 void CSecModUIModel::LoadTokenLabelsL(CEikTextListBox& aListBox)
       
   313     {
       
   314     LOG_ENTERFN("CSecModUIModel::LoadTokenLabelsL()");
       
   315 
       
   316     TInt keyStoreCount = iAOKeyStores.Count();
       
   317 
       
   318     if (0 == keyStoreCount)
       
   319         {
       
   320         LOG_WRITE_FORMAT("keyStoreCount == %i",keyStoreCount);
       
   321         LOG_LEAVEFN("CSecModUIModel::LoadTokenLabelsL()");
       
   322         //disable the scrollbar if no keystore
       
   323         aListBox.ScrollBarFrame()->SetScrollBarVisibilityL(
       
   324 	    CEikScrollBarFrame::EOff,CEikScrollBarFrame::EOff);
       
   325         return;
       
   326         }
       
   327     TBuf<KItemLength> item;
       
   328     TBuf<KItemLength> label;
       
   329 
       
   330     CDesCArray* itemArray =
       
   331         STATIC_CAST(CDesCArray*, aListBox.Model()->ItemTextArray());
       
   332     for (TInt i = 0; i < keyStoreCount; i++)
       
   333         {
       
   334         if (iAOKeyStores[i]->Token().TokenType().Type().iUid 
       
   335             == KTokenTypeFileKeystore)
       
   336             {
       
   337             AppendResourceL(label, R_QTN_KEYSTORE_LIST_TEXT_PHONE_KEYSTORE);
       
   338             }
       
   339         else 
       
   340             {                
       
   341             label = iAOKeyStores[i]->Token().Label();
       
   342             }
       
   343         item += KTab;
       
   344         item += label;
       
   345         item += KTab;
       
   346         AppendLocationL(item, iAOKeyStores[i]->Token().TokenType().Type());
       
   347         item.SetLength(item.Length() - 1); // Remove \n from the end
       
   348         itemArray->AppendL(item);
       
   349         label.Zero();
       
   350         item.Zero();
       
   351         }
       
   352 
       
   353     LOG_LEAVEFN("CSecModUIModel::LoadTokenLabelsL()");
       
   354     }
       
   355 
       
   356 // -----------------------------------------------------------------------------
       
   357 // CSecModUIModel::CheckCodeViewStringsL(MDesCArray& aItemArray)
       
   358 // -----------------------------------------------------------------------------
       
   359 //
       
   360 void CSecModUIModel::CheckCodeViewStringsL(MDesCArray& aItemArray)
       
   361     {
       
   362     LOG_ENTERFN("CSecModUIModel::CheckCodeViewStringsL()");       
       
   363     InitAuthObjectsL();
       
   364     ListAuthObjectsL();
       
   365         
       
   366     if (0 >= iAOArray.Count())
       
   367         {
       
   368         // Handle error
       
   369         }
       
   370     else if (1 == iAOArray.Count())
       
   371         {
       
   372         // Only PIN-G exists, let's remove "signing codes" from the list
       
   373         CDesCArray* itemArray = STATIC_CAST(CDesCArray*, &aItemArray);
       
   374         itemArray->Delete(1); // signing code is in the second position
       
   375         }
       
   376     else
       
   377         {
       
   378         // Do nothing
       
   379         }
       
   380     LOG_LEAVEFN("CSecModUIModel::CheckCodeViewStringsL()");
       
   381     }
       
   382 
       
   383 // -----------------------------------------------------------------------------
       
   384 // CSecModUIModel::InitAuthObjectsL()
       
   385 // -----------------------------------------------------------------------------
       
   386 //
       
   387 void CSecModUIModel::InitAuthObjectsL()
       
   388     {
       
   389     LOG_ENTERFN("CSecModUIModel::InitAuthObjectsL()");
       
   390     TInt err = KErrNone;
       
   391     // Symbian's file key store does not support
       
   392     // MCTAuthenticationObjectList interface, so we need to use
       
   393     // other way to get AO.
       
   394     if (iKeyStore->Token().TokenType().Type().iUid == KTokenTypeFileKeystore)
       
   395         {
       
   396         if (iAOArray.Count()==0)
       
   397             {
       
   398             RMPointerArray<CCTKeyInfo> keyInfos;
       
   399             CleanupClosePushL(keyInfos);
       
   400             TCTKeyAttributeFilter filter;
       
   401             TInt keyInfoCount = 0;
       
   402             filter.iPolicyFilter = TCTKeyAttributeFilter::EAllKeys;
       
   403             err = iWrapper->ListKeys(*iKeyStore, keyInfos, filter);
       
   404             ShowErrorNoteL(err);
       
   405             User::LeaveIfError(err);
       
   406             keyInfoCount = keyInfos.Count();
       
   407             for (TInt j = 0; j < keyInfoCount; j++)
       
   408                 {
       
   409                 // Check that keystore has at least one AO.
       
   410                 if (NULL != keyInfos[j]->Protector())
       
   411                     {
       
   412                     // If keystore has AO, add it to the array.
       
   413                     User::LeaveIfError(iAOArray.Append(keyInfos[j]->Protector()));
       
   414                     break;
       
   415                     }
       
   416                 }
       
   417             CleanupStack::PopAndDestroy(&keyInfos);  //keyInfos
       
   418             }
       
   419         }
       
   420     else
       
   421         {
       
   422         if (NULL == iAOList)
       
   423             {
       
   424             MCTTokenInterface* tokenInterface = NULL;
       
   425             err = iWrapper->GetAuthObjectInterface(
       
   426                 iKeyStore->Token(), tokenInterface);
       
   427             if ( KErrNone != err || NULL == tokenInterface )
       
   428                 {
       
   429                 ShowErrorNoteL(err);
       
   430                 LOG_LEAVEFN("CSecModUIModel::InitAuthObjectsL()");
       
   431                 User::Leave(err);
       
   432                 }
       
   433             iAOList = (MCTAuthenticationObjectList*)tokenInterface;
       
   434             }
       
   435         }
       
   436     LOG_LEAVEFN("CSecModUIModel::InitAuthObjectsL()");
       
   437     }
       
   438 // -----------------------------------------------------------------------------
       
   439 // CSecModUIModel::ListAuthObjectsL()
       
   440 // -----------------------------------------------------------------------------
       
   441 //
       
   442 void CSecModUIModel::ListAuthObjectsL()
       
   443     {
       
   444     LOG_ENTERFN("CSecModUIModel::ListAuthObjectsL()");
       
   445     if (0 >= iAOArray.Count())
       
   446         {
       
   447         __ASSERT_ALWAYS(iAOList, Panic(EPanicNullPointer));
       
   448         TInt err = iWrapper->ListAuthObjects(*iAOList, iAOArray);
       
   449         if (err)
       
   450             {
       
   451             ShowErrorNoteL(err);
       
   452             User::Leave(err);
       
   453             }
       
   454         }
       
   455     LOG_LEAVEFN("CSecModUIModel::ListAuthObjectsL()");
       
   456     }
       
   457 
       
   458 // -----------------------------------------------------------------------------
       
   459 // CSecModUIModel::OpenTokenL(TInt aTokenIndex)
       
   460 // -----------------------------------------------------------------------------
       
   461 //
       
   462 void CSecModUIModel::OpenTokenL(TInt aTokenIndex)
       
   463     {
       
   464     LOG_ENTERFN("CSecModUIModel::OpenTokenL()");
       
   465     ResetAndDestroyAOs();
       
   466     iKeyStore = iAOKeyStores[aTokenIndex];
       
   467     ((CAknViewAppUi*)iAvkonAppUi)->ActivateLocalViewL(KSecModUIViewCodeId);
       
   468     LOG_LEAVEFN("CSecModUIModel::OpenTokenL()");
       
   469     }
       
   470 
       
   471 // -----------------------------------------------------------------------------
       
   472 // CSecModUIModel::OpenAuthObjViewL(TInt aIndex)
       
   473 // -----------------------------------------------------------------------------
       
   474 //
       
   475 void CSecModUIModel::OpenAuthObjViewL(TInt aIndex)
       
   476     {
       
   477     LOG_ENTERFN("CSecModUIModel::OpenAuthObjViewL()");
       
   478     if (KPinGSettIndex==aIndex)
       
   479         {
       
   480         ((CAknViewAppUi*)iAvkonAppUi)->ActivateLocalViewL(KSecModUIViewAccessId);
       
   481         }
       
   482     else if (KPinNrSettIndex==aIndex)
       
   483         {
       
   484         ((CAknViewAppUi*)iAvkonAppUi)->
       
   485             ActivateLocalViewL(KSecModUIViewSignatureId);
       
   486         }
       
   487     else
       
   488         {
       
   489 
       
   490         }
       
   491     LOG_LEAVEFN("CSecModUIModel::OpenAuthObjViewL()");
       
   492     }
       
   493 
       
   494 // -----------------------------------------------------------------------------
       
   495 // CSecModUIModel::CloseAuthObjL(TInt aIndex)
       
   496 // -----------------------------------------------------------------------------
       
   497 //
       
   498 void CSecModUIModel::CloseAuthObjL(TInt aIndex)
       
   499     {
       
   500     LOG_ENTERFN("CSecModUIModel::CloseAuthObjL()");
       
   501     if (PinOpen(aIndex))
       
   502         {
       
   503         __ASSERT_ALWAYS(aIndex < iAOArray.Count(), Panic(EPanicIndexOutOfRange));
       
   504         TInt err = iWrapper->CloseAuthObject(*(iAOArray[aIndex]));
       
   505         if (err)
       
   506             {
       
   507             ShowErrorNoteL(err);
       
   508             User::Leave(err);
       
   509             }
       
   510         }
       
   511     LOG_LEAVEFN("CSecModUIModel::CloseAuthObjL()");
       
   512     }
       
   513 
       
   514 
       
   515 // -----------------------------------------------------------------------------
       
   516 // CSecModUIModel::ViewSecModDetailsL(TInt aTokenIndex)
       
   517 // -----------------------------------------------------------------------------
       
   518 //
       
   519 void CSecModUIModel::ViewSecModDetailsL(TInt aTokenIndex)
       
   520     {
       
   521     LOG_ENTERFN("CSecModUIModel::ViewSecModDetailsL(TInt aTokenIndex)");
       
   522     iKeyStore = iAOKeyStores[aTokenIndex];
       
   523     InitAuthObjectsL();
       
   524     ListAuthObjectsL();
       
   525     ViewOpenedSecModDetailsL();
       
   526     iKeyStore = NULL; // not owned
       
   527     if (iAOList)
       
   528         {
       
   529         iAOList->Release();
       
   530         iAOList = NULL;
       
   531         }
       
   532     iAOArray.Reset();
       
   533 
       
   534     LOG_LEAVEFN("CSecModUIModel::ViewSecModDetailsL(TInt aTokenIndex)");
       
   535     }
       
   536 
       
   537 // -----------------------------------------------------------------------------
       
   538 // CSecModUIModel::ViewOpenedSecModDetailsL()
       
   539 // -----------------------------------------------------------------------------
       
   540 //
       
   541 void CSecModUIModel::ViewOpenedSecModDetailsL()
       
   542     {
       
   543     LOG_ENTERFN("CSecModUIModel::ViewSecModDetailsL()");
       
   544     // Create message buffer
       
   545     HBufC* message = HBufC::NewLC(KMaxLengthTextDetailsBody);
       
   546     TPtr messagePtr = message->Des();
       
   547     MCTToken& token = iKeyStore->Token();
       
   548     
       
   549     if (token.TokenType().Type().iUid == KTokenTypeFileKeystore)
       
   550         { 
       
   551         AppendItemL(messagePtr, R_QTN_WIM_NAME,
       
   552             KNullDesC, R_QTN_KEYSTORE_LIST_TEXT_PHONE_KEYSTORE);        
       
   553         }
       
   554     else 
       
   555         {            
       
   556         AppendItemL(messagePtr, R_QTN_WIM_NAME,
       
   557             token.Label(), R_TEXT_RESOURCE_VIEW_NO_LABEL_DETAILS);
       
   558         }
       
   559 
       
   560     AppendItemL(messagePtr, R_QTN_WIM_CARD_VERSION,
       
   561         token.Information( MCTToken::EVersion ),
       
   562         R_TEXT_RESOURCE_DETAILS_VIEW_NOT_DEFINED );
       
   563 
       
   564     AppendLocationL(messagePtr, token.TokenType().Type(), R_QTN_WIM_SECURITY_MODULE_LOCATION);
       
   565     messagePtr.Append(KEnter); // AppendLocationL does not add enter as others
       
   566     
       
   567     if (token.TokenType().Type().iUid == KTokenTypeFileKeystore)
       
   568         { 
       
   569         AppendItemL(messagePtr, R_QTN_WIM_SETT_PIN_G,
       
   570             KNullDesC, R_QTN_SECMOD_TITLE_PHONE_KEYSTORE_CODE);        
       
   571         }
       
   572     else 
       
   573         {            
       
   574         AppendItemL(messagePtr, R_QTN_WIM_SETT_PIN_G,
       
   575             iAOArray[0]->Label(), R_QTN_WIM_PIN_G_NO_LABEL_DETAILS);
       
   576         }
       
   577 
       
   578     AppendPinNRsL(messagePtr);
       
   579 
       
   580     AppendItemL(messagePtr, R_QTN_WIM_SERIAL_NRO,
       
   581         token.Information( MCTToken::ESerialNo),
       
   582         R_TEXT_RESOURCE_DETAILS_VIEW_NOT_DEFINED);
       
   583 
       
   584     AppendItemL(messagePtr, R_QTN_WIM_MANUF,
       
   585         token.Information( MCTToken::EManufacturer),
       
   586         R_TEXT_RESOURCE_DETAILS_VIEW_NOT_DEFINED);
       
   587 
       
   588     CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL(*message);
       
   589     dlg->PrepareLC(R_SECMOD_DETAILS_VIEW);
       
   590     dlg->RunLD();
       
   591     CleanupStack::PopAndDestroy(message);
       
   592     LOG_LEAVEFN("CSecModUIModel::ViewSecModDetailsL()");
       
   593     }
       
   594 
       
   595 // -----------------------------------------------------------------------------
       
   596 // CSecModUIModel::AppendPinNRsL(TDes& aMessage) const
       
   597 // -----------------------------------------------------------------------------
       
   598 //
       
   599 void CSecModUIModel::AppendPinNRsL(TDes& aMessage) const
       
   600     {
       
   601     TInt pinCount = iAOArray.Count();
       
   602     HBufC* value = NULL;
       
   603     TInt j = 1;
       
   604 
       
   605     for (TInt i=1; i<pinCount; i++)
       
   606       {
       
   607       AppendResourceAndEnterL(aMessage, R_QTN_WIM_KEY_PIN);
       
   608       if (iAOArray[i]->Label().Length() > 0)
       
   609           {
       
   610           aMessage.Append(iAOArray[i]->Label());
       
   611           }
       
   612       else
       
   613           {
       
   614           value = StringLoader::LoadLC(R_QTN_WIM_PIN_NR_NO_LABEL_DETAILS, j);
       
   615           aMessage.Append(*value);
       
   616           j++;
       
   617           }
       
   618       aMessage.Append(KDoubleEnter);
       
   619       }
       
   620     }
       
   621 
       
   622 // -----------------------------------------------------------------------------
       
   623 // CSecModUIModel::AppendLocationL(...)
       
   624 // -----------------------------------------------------------------------------
       
   625 //
       
   626 void CSecModUIModel::AppendLocationL(
       
   627     TDes& aMessage,
       
   628     TUid aUid,
       
   629     TInt aItemRes) const
       
   630     {
       
   631     TInt location = 0;
       
   632 
       
   633 
       
   634     switch ( aUid.iUid )
       
   635         {
       
   636         case KTokenTypeFileKeystore:
       
   637             {
       
   638             location = R_TEXT_RESOURCE_DETAILS_VIEW_LOCATION_PHONE_MEMORY;
       
   639             break;
       
   640             }
       
   641         case KWIMStoreUid:
       
   642             {
       
   643             location = R_TEXT_RESOURCE_DETAILS_VIEW_LOCATION_SMART_CARD;
       
   644             break;
       
   645             }
       
   646         default:
       
   647             {
       
   648             break;
       
   649             }
       
   650         }
       
   651     if (0 != aItemRes)
       
   652         {
       
   653         AppendResourceAndEnterL(aMessage, aItemRes);
       
   654         }
       
   655     AppendResourceAndEnterL(aMessage, location);
       
   656     }
       
   657 
       
   658 // -----------------------------------------------------------------------------
       
   659 // CSecModUIModel::AppendItemL(...)
       
   660 // -----------------------------------------------------------------------------
       
   661 //
       
   662 void CSecModUIModel::AppendItemL(
       
   663     TDes& aMessage,
       
   664     TInt aResItem,
       
   665     const TDesC& aValue,
       
   666     TInt aResNotDefined) const
       
   667     {
       
   668     AppendResourceAndEnterL(aMessage, aResItem);
       
   669     AppendValueL(aMessage, aValue, aResNotDefined);
       
   670     aMessage.Append(KEnter);
       
   671     }
       
   672 
       
   673 // ---------------------------------------------------------
       
   674 // CSecModUIModel::AppendResourceL(TDes& aMessage, TInt aResource)
       
   675 // Appends aResource to aMessage
       
   676 // ---------------------------------------------------------
       
   677 //
       
   678 void CSecModUIModel::AppendResourceL(TDes& aMessage, TInt aResource) const
       
   679   {
       
   680   HBufC* stringHolder = StringLoader::LoadLC(aResource);
       
   681   aMessage.Append(*stringHolder);
       
   682   CleanupStack::PopAndDestroy(stringHolder);  
       
   683   }
       
   684   
       
   685 // ---------------------------------------------------------
       
   686 // CSecModUIModel::AppendResourceL(TDes& aMessage, TInt aResource)
       
   687 // Appends aResource to aMessage
       
   688 // ---------------------------------------------------------
       
   689 //
       
   690 void CSecModUIModel::AppendResourceAndEnterL(TDes& aMessage, TInt aResource) const
       
   691   {
       
   692   HBufC* stringHolder = StringLoader::LoadLC(aResource);
       
   693   aMessage.Append(*stringHolder);
       
   694   CleanupStack::PopAndDestroy(stringHolder);
       
   695   aMessage.Append(KEnter);
       
   696   }
       
   697 
       
   698 // -----------------------------------------------------------------------------
       
   699 // CSecModUIModel::AppendValueL(...)
       
   700 // -----------------------------------------------------------------------------
       
   701 //
       
   702 void CSecModUIModel::AppendValueL(
       
   703     TDes& aMessage,
       
   704     const TDesC& aValue,
       
   705     TInt aResNotDefined) const
       
   706   {
       
   707   HBufC* buf = HBufC::NewLC(KMaxLengthItemValue);
       
   708   buf->Des() = aValue;
       
   709   buf->Des().TrimLeft();
       
   710   TInt length = buf->Des().Length();
       
   711   if (length == 0 )
       
   712     {
       
   713     AppendResourceAndEnterL(aMessage, aResNotDefined);
       
   714     }
       
   715   else
       
   716     {
       
   717     aMessage.Append(*buf);
       
   718     aMessage.Append(KEnter);
       
   719     }
       
   720   CleanupStack::PopAndDestroy(buf);
       
   721   }
       
   722 
       
   723 // -----------------------------------------------------------------------------
       
   724 // CSecModUIModel::DeleteKeyStoreL(TInt aTokenIndex)
       
   725 // -----------------------------------------------------------------------------
       
   726 //
       
   727 TBool CSecModUIModel::DeleteKeyStoreL(TInt aTokenIndex)
       
   728     {
       
   729     LOG_ENTERFN("CSecModUIModel::DeleteKeyStoreL()");
       
   730     __ASSERT_ALWAYS(aTokenIndex < iAOKeyStores.Count(), Panic(EPanicIndexOutOfRange));
       
   731     // ask confirmation from the user
       
   732     if (ShowConfirmationQueryL(R_QTN_CM_CONFIRM_DELETE_KEYS))
       
   733         {
       
   734         RMPointerArray<CCTKeyInfo> keyInfos;
       
   735         CleanupClosePushL(keyInfos);
       
   736         TCTKeyAttributeFilter filter;
       
   737         filter.iPolicyFilter = TCTKeyAttributeFilter::EAllKeys;
       
   738         TInt err = iWrapper->ListKeys(*iAOKeyStores[aTokenIndex], keyInfos, filter);
       
   739         ShowErrorNoteL(err);
       
   740         User::LeaveIfError(err);
       
   741         for (TInt i = 0; i < keyInfos.Count(); ++i)
       
   742             {
       
   743             err = iWrapper->DeleteKey(*iUnifiedKeyStore, keyInfos[i]->Handle());
       
   744             ShowErrorNoteL(err);
       
   745 
       
   746             if (KErrHardwareNotAvailable == err )
       
   747                 {
       
   748                 break; // Break the loop, if keystore not available
       
   749                 }
       
   750             }
       
   751         CleanupStack::PopAndDestroy(&keyInfos);  //keyInfos
       
   752         ResetAndDestroyCTObjects();
       
   753         InitializeKeyStoreL();
       
   754         LOG_LEAVEFN("CSecModUIModel::DeleteKeyStoreL()");
       
   755         return ETrue;
       
   756         }
       
   757     else
       
   758         {
       
   759         LOG_LEAVEFN("CSecModUIModel::DeleteKeyStoreL()");
       
   760         return EFalse;
       
   761         }
       
   762     }
       
   763 
       
   764 // -----------------------------------------------------------------------------
       
   765 // CSecModUIModel::IsTokenDeletable(TInt aTokenIndex)
       
   766 // -----------------------------------------------------------------------------
       
   767 //
       
   768 TBool CSecModUIModel::IsTokenDeletable(TInt aTokenIndex)
       
   769     {
       
   770     LOG_ENTERFN("CSecModUIModel::IsTokenDeletable()");
       
   771     __ASSERT_ALWAYS(aTokenIndex < iAOKeyStores.Count(), Panic(EPanicIndexOutOfRange));
       
   772     TBool ret = EFalse;
       
   773     if (iAOKeyStores[aTokenIndex]->Token().TokenType().Type().iUid
       
   774         == KTokenTypeFileKeystore)
       
   775         {
       
   776         ret = ETrue;
       
   777         }
       
   778     else
       
   779         {
       
   780         ret = EFalse;
       
   781         }
       
   782     LOG_LEAVEFN("CSecModUIModel::IsTokenDeletable()");
       
   783     return ret;
       
   784     }
       
   785 
       
   786 // -----------------------------------------------------------------------------
       
   787 // CSecModUIModel::LoadPinNRLabelsL(...)
       
   788 // -----------------------------------------------------------------------------
       
   789 //
       
   790 void CSecModUIModel::LoadPinNRLabelsL(CEikTextListBox& aListBox, TBool aShowBlockedNote)
       
   791     {
       
   792     LOG_ENTERFN("CSecModUIModel::LoadPinNRLabelsL()");
       
   793     TBuf<KMaxSettItemSize> item;
       
   794     TBuf<KMaxSettItemSize> label;
       
   795     CDesCArray* itemArray = STATIC_CAST(CDesCArray*, aListBox.Model()->ItemTextArray());
       
   796     itemArray->Reset();
       
   797 
       
   798     LOG_WRITE_FORMAT("CSecModUIModel::LoadPinNRLabelsL, iAOArray.Count() == %i",iAOArray.Count());
       
   799     TUint32 status = 0;
       
   800     // Here is assumed that the first AO is always PIN-G
       
   801     for (TInt i = 1; i < iAOArray.Count(); i++)
       
   802         {
       
   803         label = iAOArray[i]->Label();
       
   804         status = iAOArray[i]->Status();
       
   805         LOG_WRITE_FORMAT("PIN-NR status == %i", status);
       
   806         if (status & EAuthObjectBlocked)
       
   807             {
       
   808             if (aShowBlockedNote)
       
   809                 {
       
   810                 if (status & EUnblockDisabled)
       
   811                     {
       
   812                     ShowInformationNoteL(R_QTN_WIM_PIN_TOTALBLOCKED, label);
       
   813                     }
       
   814                 else
       
   815                     {
       
   816                     ShowInformationNoteL(R_QTN_WIM_ERR_PIN_BLOCKED, label);
       
   817                     }
       
   818                 }
       
   819             HBufC* value = StringLoader::LoadLC(R_QTN_WIM_STATUS_BLOCKED);
       
   820             CreateSettingItem(label, *value, item );
       
   821             CleanupStack::PopAndDestroy(value);
       
   822             }
       
   823         else
       
   824             {
       
   825             CreateSettingItem(label, KFourAsterisks, item);
       
   826             }
       
   827         itemArray->AppendL(item);
       
   828         label.Zero();
       
   829         item.Zero();
       
   830         }
       
   831     LOG_LEAVEFN("CSecModUIModel::LoadPinNRLabelsL()");
       
   832     }
       
   833 
       
   834 // -----------------------------------------------------------------------------
       
   835 // CSecModUIModel::LoadPinGItemsL(CEikTextListBox& aListBox)
       
   836 // -----------------------------------------------------------------------------
       
   837 //
       
   838 void CSecModUIModel::LoadPinGItemsL(CEikTextListBox& aListBox)
       
   839     {
       
   840     LOG_ENTERFN("CSecModUIModel::LoadPinGItemsL()");
       
   841     TBuf<KMaxSettItemSize> item;
       
   842     TBuf<KMaxSettItemSize> label;
       
   843 
       
   844     CDesCArray* itemArray = STATIC_CAST(CDesCArray*,
       
   845         aListBox.Model()->ItemTextArray());
       
   846 
       
   847     if (iKeyStore->Token().TokenType().Type().iUid 
       
   848         == KTokenTypeFileKeystore)
       
   849         {
       
   850         AppendResourceL(label, R_QTN_SECMOD_TITLE_PHONE_KEYSTORE_CODE);
       
   851         }
       
   852     else
       
   853         {                
       
   854         label = iAOArray[KPinGIndex]->Label();
       
   855         }
       
   856     CreateSettingItem(label, KFourAsterisks, item);
       
   857     itemArray->AppendL(item);
       
   858     item.Zero();
       
   859     PINRequestItemL(KPinGIndex, item);
       
   860     itemArray->AppendL(item);
       
   861     item.Zero();
       
   862     PINStatusItemL(KPinGIndex, item, ETrue);
       
   863     itemArray->AppendL(item);
       
   864     LOG_LEAVEFN("CSecModUIModel::LoadPinGItemsL()");
       
   865     }
       
   866 
       
   867 // -----------------------------------------------------------------------------
       
   868 // CSecModUIModel::PINRequestItemL(...)
       
   869 // -----------------------------------------------------------------------------
       
   870 //
       
   871 void CSecModUIModel::PINRequestItemL(TInt aIndex, TDes& aItem) const
       
   872     {
       
   873     LOG_ENTERFN("CSecModUIModel::PINRequestItemL()");
       
   874     __ASSERT_ALWAYS(aIndex < iAOArray.Count(), Panic(EPanicIndexOutOfRange));
       
   875     TUint32 status = iAOArray[aIndex]->Status();
       
   876     HBufC* title = NULL;
       
   877     HBufC* value = NULL;
       
   878     title = StringLoader::LoadLC(R_QTN_WIM_PIN_REQUEST);
       
   879 
       
   880     if (status & EEnabled)
       
   881         {
       
   882         value = StringLoader::LoadLC(R_QTN_WIM_REQUEST_ON);
       
   883         CreateSettingItem(*title, *value, aItem );
       
   884         }
       
   885     else
       
   886         {
       
   887         value = StringLoader::LoadLC(R_QTN_WIM_REQUEST_OFF);
       
   888         CreateSettingItem(*title, *value, aItem );
       
   889         }
       
   890     CleanupStack::PopAndDestroy(2, title);
       
   891     LOG_LEAVEFN("CSecModUIModel::PINRequestItemL()");
       
   892     }
       
   893 
       
   894 // -----------------------------------------------------------------------------
       
   895 // CSecModUIModel::PINStatusItemL(...)
       
   896 // -----------------------------------------------------------------------------
       
   897 //
       
   898 void CSecModUIModel::PINStatusItemL(
       
   899     TInt aIndex,
       
   900     TDes& aItem,
       
   901     TBool aShowBlockedNote) const
       
   902     {
       
   903     LOG_ENTERFN("CSecModUIModel::PINStatusItemL()");
       
   904     __ASSERT_ALWAYS(aIndex < iAOArray.Count(), Panic(EPanicIndexOutOfRange));
       
   905     TUint32 status = iAOArray[aIndex]->Status();
       
   906     HBufC* title = NULL;
       
   907     HBufC* value = NULL;
       
   908     title = StringLoader::LoadLC(R_QTN_WIM_SETT_STATUS);
       
   909 
       
   910     LOG_WRITE_FORMAT("PIN-G status == %i", status);
       
   911 
       
   912     if (status & EAuthObjectBlocked)
       
   913         {
       
   914         if (aShowBlockedNote)
       
   915             {
       
   916             if (status & EUnblockDisabled)
       
   917                 {
       
   918                 ShowInformationNoteL(
       
   919                     R_QTN_WIM_PIN_TOTALBLOCKED, iAOArray[aIndex]->Label());
       
   920                 }
       
   921             else
       
   922                 {
       
   923                 ShowInformationNoteL(
       
   924                     R_QTN_WIM_ERR_PIN_BLOCKED, iAOArray[aIndex]->Label());
       
   925                 }
       
   926             }            
       
   927         value = StringLoader::LoadLC(R_QTN_SECMOD_STATUS_VALUE_BLOCKED);
       
   928         }
       
   929     else if ( PinOpen(aIndex) )
       
   930         {
       
   931         value = StringLoader::LoadLC(R_QTN_WIM_OPT_OPEN);
       
   932         }
       
   933     else
       
   934         {
       
   935         value = StringLoader::LoadLC(R_QTN_WIM_STATUS_CLOSED);
       
   936         }
       
   937     CreateSettingItem(*title, *value, aItem );
       
   938     CleanupStack::PopAndDestroy(2, title);
       
   939     LOG_LEAVEFN("CSecModUIModel::PINStatusItemL()");
       
   940     }
       
   941 
       
   942 // -----------------------------------------------------------------------------
       
   943 // CSecModUIModel::CreateSettingItem(...)
       
   944 // -----------------------------------------------------------------------------
       
   945 //
       
   946 void CSecModUIModel::CreateSettingItem(
       
   947     const TDesC& aTitle, const TDesC& aValue, TDes& aItem) const
       
   948   {
       
   949     LOG_ENTERFN("CSecModUIModel::CreateSettingItem()");
       
   950     aItem += KTab;
       
   951     aItem += aTitle;
       
   952     aItem += KDoubleTab;
       
   953     aItem += aValue;
       
   954     LOG_LEAVEFN("CSecModUIModel::CreateSettingItem()");
       
   955   }
       
   956 
       
   957 // -----------------------------------------------------------------------------
       
   958 // CSecModUIModel::eOrUnblockPinNrL(TInt aIndex)
       
   959 // -----------------------------------------------------------------------------
       
   960 //
       
   961 void CSecModUIModel::ChangeOrUnblockPinNrL(TInt aIndex)
       
   962     {
       
   963     LOG_ENTERFN("CSecModUIModel::ChangeOrUnblockPinNrL()");
       
   964     // Add PIN-G to the list
       
   965     ChangeOrUnblockPinL(aIndex+1);
       
   966     LOG_LEAVEFN("CSecModUIModel::ChangeOrUnblockPinNrL()");
       
   967     }
       
   968 
       
   969 // -----------------------------------------------------------------------------
       
   970 // CSecModUIModel::ChangeOrUnblockPinL(TInt aIndex)
       
   971 // -----------------------------------------------------------------------------
       
   972 //
       
   973 void CSecModUIModel::ChangeOrUnblockPinL(TInt aIndex)
       
   974     {
       
   975     LOG_ENTERFN("CSecModUIModel::ChangeOrUnblockPinL()");
       
   976     __ASSERT_ALWAYS(aIndex < iAOArray.Count(), Panic(EPanicIndexOutOfRange));
       
   977     TUint32 status = iAOArray[aIndex]->Status();
       
   978 
       
   979     if ((status & EAuthObjectBlocked) && (status & EUnblockDisabled))
       
   980         {
       
   981         return; // We cannot do anything. PIN is total bolcked.
       
   982         }
       
   983     else if (status & EAuthObjectBlocked)
       
   984         {
       
   985         // Let's unblock the PIN
       
   986         UnblockPinL(aIndex);
       
   987         }
       
   988     else if (status & EChangeDisabled)
       
   989         {
       
   990         // We cannot do anything. Change is disabled.
       
   991         }
       
   992      else if (status & EEnabled)
       
   993         {
       
   994         // PIN is enabled. Let's change the PIN.
       
   995         ChangePinL(aIndex);
       
   996         }
       
   997      else
       
   998         {
       
   999         // PIN is disabled. Not possible to change PIN.
       
  1000         }
       
  1001     LOG_LEAVEFN("CSecModUIModel::ChangeOrUnblockPinL()");
       
  1002     }
       
  1003 
       
  1004 // -----------------------------------------------------------------------------
       
  1005 // CSecModUIModel::ChangePinNrL(TInt aIndex)
       
  1006 // -----------------------------------------------------------------------------
       
  1007 //
       
  1008 void CSecModUIModel::ChangePinNrL(TInt aIndex)
       
  1009     {
       
  1010     LOG_ENTERFN("CSecModUIModel::ChangePinNrL()");
       
  1011     ChangePinL(aIndex+1);
       
  1012     LOG_LEAVEFN("CSecModUIModel::ChangePinNrL()");
       
  1013     }
       
  1014 
       
  1015 // -----------------------------------------------------------------------------
       
  1016 // CSecModUIModel::ChangePinL(TInt aIndex)
       
  1017 // -----------------------------------------------------------------------------
       
  1018 //
       
  1019 void CSecModUIModel::ChangePinL(TInt aIndex)
       
  1020     {
       
  1021     LOG_ENTERFN("CSecModUIModel::ChangePinL()");
       
  1022     __ASSERT_ALWAYS(aIndex < iAOArray.Count(), Panic(EPanicIndexOutOfRange));
       
  1023     TInt err = KErrNone;
       
  1024   
       
  1025     err = iWrapper->ChangeReferenceData(*(iAOArray[aIndex]));
       
  1026     if (err)
       
  1027         {
       
  1028         ShowErrorNoteL(err);
       
  1029         }
       
  1030     else
       
  1031         {
       
  1032         ShowConfirmationNoteL(R_QTN_WIM_INFO_PIN_CHANGED);
       
  1033         }
       
  1034     
       
  1035     LOG_LEAVEFN("CSecModUIModel::ChangePinL()");
       
  1036     }
       
  1037 
       
  1038 // -----------------------------------------------------------------------------
       
  1039 // CSecModUIModel::UnblockPinNrL(TInt aIndex)
       
  1040 // -----------------------------------------------------------------------------
       
  1041 //
       
  1042 void CSecModUIModel::UnblockPinNrL(TInt aIndex)
       
  1043     {
       
  1044     LOG_ENTERFN("CSecModUIModel::UnblockPinNrL()");
       
  1045     UnblockPinL(aIndex+1);
       
  1046     LOG_LEAVEFN("CSecModUIModel::UnblockPinNrL()");
       
  1047     }
       
  1048 
       
  1049 // -----------------------------------------------------------------------------
       
  1050 // CSecModUIModel::UnblockPinL(TInt aIndex)
       
  1051 // -----------------------------------------------------------------------------
       
  1052 //
       
  1053 void CSecModUIModel::UnblockPinL(TInt aIndex)
       
  1054     {
       
  1055     LOG_ENTERFN("CSecModUIModel::UnblockPinL()");
       
  1056     __ASSERT_ALWAYS(aIndex < iAOArray.Count(), Panic(EPanicIndexOutOfRange));
       
  1057     TInt err = iWrapper->UnblockAuthObject(*(iAOArray[aIndex]));
       
  1058     if (KErrNone == err)
       
  1059         {
       
  1060         ShowConfirmationNoteL(R_QTN_WIM_INFO_PIN_UNBLOCKED);
       
  1061         }
       
  1062     else
       
  1063         {
       
  1064         ShowErrorNoteL(err);
       
  1065         }
       
  1066     LOG_LEAVEFN("CSecModUIModel::UnblockPinL()");
       
  1067     }
       
  1068 
       
  1069 // -----------------------------------------------------------------------------
       
  1070 // CSecModUIModel::PinNrChangeable(TInt aIndex) const
       
  1071 // -----------------------------------------------------------------------------
       
  1072 //
       
  1073 TBool CSecModUIModel::PinNrChangeable(TInt aIndex) const
       
  1074     {
       
  1075     // Add PIN-G to the list
       
  1076     return PinChangeable(aIndex+1);
       
  1077     }
       
  1078 // -----------------------------------------------------------------------------
       
  1079 // CSecModUIModel::PinChangeable(TInt aIndex) const
       
  1080 // -----------------------------------------------------------------------------
       
  1081 //
       
  1082 TBool CSecModUIModel::PinChangeable(TInt aIndex) const
       
  1083     {
       
  1084     LOG_ENTERFN("CSecModUIModel::PinChangeable()");
       
  1085     __ASSERT_ALWAYS(aIndex < iAOArray.Count(), Panic(EPanicIndexOutOfRange));
       
  1086     TUint32 status = iAOArray[aIndex]->Status();
       
  1087     TBool ret = ETrue;
       
  1088     if ( (status & EAuthObjectBlocked) || (status & EChangeDisabled) )
       
  1089     //if ( status & (EAuthObjectBlocked | EChangeDisabled))
       
  1090         {
       
  1091         ret = EFalse;
       
  1092         }
       
  1093     else if ( status & EEnabled )
       
  1094         {
       
  1095         ret = ETrue;
       
  1096         }
       
  1097     else // PIN is disabled;
       
  1098         {
       
  1099         ret = EFalse;
       
  1100         }
       
  1101     LOG_LEAVEFN("CSecModUIModel::PinChangeable()");
       
  1102     return ret;
       
  1103     }
       
  1104 // -----------------------------------------------------------------------------
       
  1105 // CSecModUIModel::PinNrUnblockable(TInt aIndex) const
       
  1106 // -----------------------------------------------------------------------------
       
  1107 //
       
  1108 TBool CSecModUIModel::PinNrUnblockable(TInt aIndex) const
       
  1109     {
       
  1110     // Add PIN-G to the list
       
  1111     return PinUnblockable(aIndex+1);
       
  1112     }
       
  1113 
       
  1114 // -----------------------------------------------------------------------------
       
  1115 // CSecModUIModel::PinUnblockable(TInt aIndex) const
       
  1116 // -----------------------------------------------------------------------------
       
  1117 //
       
  1118 TBool CSecModUIModel::PinUnblockable(TInt aIndex) const
       
  1119     {
       
  1120     LOG_ENTERFN("CSecModUIModel::PinUnblockable()");
       
  1121     TUint32 status = iAOArray[aIndex]->Status();
       
  1122     TBool ret = ETrue;
       
  1123     if ( status & EUnblockDisabled )
       
  1124         {
       
  1125         ret = EFalse;
       
  1126         }
       
  1127     else if ( status & EAuthObjectBlocked )
       
  1128         {
       
  1129         ret = ETrue;
       
  1130         }
       
  1131     else // PIN is not blocked;
       
  1132         {
       
  1133         ret = EFalse;
       
  1134         }
       
  1135     LOG_LEAVEFN("CSecModUIModel::PinUnblockable()");
       
  1136     return ret;
       
  1137     }
       
  1138 
       
  1139 // -----------------------------------------------------------------------------
       
  1140 // CSecModUIModel::PinOpen(TInt aIndex) const
       
  1141 // -----------------------------------------------------------------------------
       
  1142 //
       
  1143 TBool CSecModUIModel::PinOpen(TInt aIndex) const
       
  1144     {
       
  1145     LOG_ENTERFN("CSecModUIModel::PinOpen()");
       
  1146     __ASSERT_ALWAYS(aIndex < iAOArray.Count(), Panic(EPanicIndexOutOfRange));
       
  1147     TInt timeRemaining = 0;
       
  1148     TInt err = iWrapper->TimeRemaining(*(iAOArray[aIndex]), timeRemaining);
       
  1149     TBool ret = ETrue;
       
  1150     if ( 0 < timeRemaining )
       
  1151         {
       
  1152         ret = ETrue;
       
  1153         }
       
  1154     else if( timeRemaining == -1 )
       
  1155         {
       
  1156         ret = ETrue;
       
  1157         }
       
  1158     else
       
  1159         {
       
  1160         ret = EFalse;
       
  1161         }
       
  1162     LOG_LEAVEFN("CSecModUIModel::PinOpen()");
       
  1163     return ret;
       
  1164     }
       
  1165 
       
  1166 // -----------------------------------------------------------------------------
       
  1167 // CSecModUIModel::ChangeCodeRequestL(TInt aIndex)
       
  1168 // -----------------------------------------------------------------------------
       
  1169 //
       
  1170 TInt CSecModUIModel::ChangeCodeRequestL(TInt aIndex)
       
  1171     {
       
  1172     LOG_ENTERFN("CSecModUIModel::ChangeCodeRequestL()");
       
  1173     __ASSERT_ALWAYS(aIndex < iAOArray.Count(), Panic(EPanicIndexOutOfRange));
       
  1174     TUint32 status = iAOArray[aIndex]->Status();
       
  1175     TInt err = KErrNone;
       
  1176     if (status & EDisableAllowed &&  !(status & EAuthObjectBlocked))
       
  1177         {
       
  1178         if ( status & EEnabled )
       
  1179             {
       
  1180             err = iWrapper->DisableAuthObject(*(iAOArray[aIndex]));
       
  1181             }
       
  1182         else
       
  1183             {
       
  1184             err = iWrapper->EnableAuthObject(*(iAOArray[aIndex]));
       
  1185             }
       
  1186         ShowErrorNoteL(err);
       
  1187         }
       
  1188     LOG_LEAVEFN("CSecModUIModel::ChangeCodeRequestL()");
       
  1189     return err;
       
  1190     }
       
  1191 
       
  1192 // -----------------------------------------------------------------------------
       
  1193 // CSecModUIModel::PinRequestChangeable(TInt aIndex) const
       
  1194 // -----------------------------------------------------------------------------
       
  1195 //
       
  1196 TBool CSecModUIModel::PinRequestChangeable(TInt aIndex) const
       
  1197     {
       
  1198     LOG_ENTERFN("CSecModUIModel::PinRequestChangeable()");
       
  1199     __ASSERT_ALWAYS(aIndex < iAOArray.Count(), Panic(EPanicIndexOutOfRange));
       
  1200     TUint32 status = iAOArray[aIndex]->Status();
       
  1201     TBool ret = EFalse;
       
  1202     if ( status & EAuthObjectBlocked )
       
  1203         {
       
  1204         ret = EFalse;
       
  1205         }
       
  1206     else if ( status & EDisableAllowed )
       
  1207         {
       
  1208         ret = ETrue;
       
  1209         }
       
  1210     else // Disable not allowed;
       
  1211         {
       
  1212         ret = EFalse;
       
  1213         }
       
  1214     LOG_LEAVEFN("CSecModUIModel::PinRequestChangeable()");
       
  1215     return ret;
       
  1216     }
       
  1217 
       
  1218 // -----------------------------------------------------------------------------
       
  1219 // CSecModUIModel::ShowErrorNoteL(TInt aError) const
       
  1220 // -----------------------------------------------------------------------------
       
  1221 //
       
  1222 void CSecModUIModel::ShowErrorNoteL(TInt aError) const
       
  1223     {
       
  1224     LOG_ENTERFN("CSecModUIModel::ShowErrorNoteL()");
       
  1225     HBufC* text = NULL;
       
  1226 
       
  1227     switch (aError)
       
  1228         {
       
  1229         case KErrCancel:
       
  1230         case KErrLocked:
       
  1231         case KErrNone:
       
  1232             {
       
  1233             LOG_WRITE_FORMAT("aError == %i",aError);
       
  1234             LOG_LEAVEFN("CSecModUIModel::ShowErrorNoteL()");
       
  1235             break;
       
  1236             }
       
  1237         case KErrInUse:
       
  1238             {
       
  1239             text = StringLoader::LoadLC(R_QTN_KEYSTORE_INFO_UNABLE_TO_DELETE);
       
  1240             break;
       
  1241             }
       
  1242         case KErrBadPassphrase:
       
  1243             {
       
  1244             text = StringLoader::LoadLC(R_QTN_WIM_ERR_WRONG_PIN);
       
  1245             break;
       
  1246             }
       
  1247         case KErrHardwareNotAvailable: // flow thru
       
  1248         default:
       
  1249             {
       
  1250             LOG_WRITE_FORMAT("ERROR: aError == %i",aError);
       
  1251             text = StringLoader::LoadLC(R_QTN_WIM_ERR_IO_ERROR);
       
  1252             break;
       
  1253             }
       
  1254         }
       
  1255 
       
  1256     if (text)
       
  1257         {
       
  1258         CAknErrorNote* note = new (ELeave) CAknErrorNote;
       
  1259         note->ExecuteLD(*text);
       
  1260         CleanupStack::PopAndDestroy(text);
       
  1261         }
       
  1262     LOG_LEAVEFN("CSecModUIModel::ShowErrorNoteL()");
       
  1263     }
       
  1264 
       
  1265 // -----------------------------------------------------------------------------
       
  1266 // CSecModUIModel::ShowConfirmationQueryL(TInt aResourceId) const
       
  1267 // -----------------------------------------------------------------------------
       
  1268 //
       
  1269 TInt CSecModUIModel::ShowConfirmationQueryL(TInt aResourceId) const
       
  1270     {
       
  1271     LOG_ENTERFN("CSecModUIModel::ShowConfirmationQueryL ()");
       
  1272     HBufC* text = NULL;
       
  1273     text = StringLoader::LoadLC(aResourceId);
       
  1274     CAknQueryDialog* dlg = CAknQueryDialog::NewL(CAknQueryDialog::ENoTone);
       
  1275     TInt selection = dlg->ExecuteLD(R_SECMOD_CONFIRMATION_QUERY_YES_NO, *text);
       
  1276     CleanupStack::PopAndDestroy(text);
       
  1277     LOG_LEAVEFN("CSecModUIModel::ShowConfirmationNoteL()");
       
  1278     return selection;
       
  1279     }
       
  1280 
       
  1281 // -----------------------------------------------------------------------------
       
  1282 // CSecModUIModel::ShowConfirmationNoteL(TInt aResourceId) const
       
  1283 // -----------------------------------------------------------------------------
       
  1284 //
       
  1285 void CSecModUIModel::ShowConfirmationNoteL(TInt aResourceId) const
       
  1286     {
       
  1287     LOG_ENTERFN("CSecModUIModel::ShowConfirmationNoteL()");
       
  1288     HBufC* text = NULL;
       
  1289     text = StringLoader::LoadLC(aResourceId);
       
  1290     CAknConfirmationNote * note = new (ELeave) CAknConfirmationNote;
       
  1291     note->ExecuteLD(*text);
       
  1292     CleanupStack::PopAndDestroy(text);
       
  1293     LOG_LEAVEFN("CSecModUIModel::ShowConfirmationNoteL()");
       
  1294     }
       
  1295 
       
  1296 // -----------------------------------------------------------------------------
       
  1297 // CSecModUIModel::ShowInformationNoteL(...)
       
  1298 // Global note needs to be used here because otherwise view might cancel
       
  1299 // the query too early when the view is activated.
       
  1300 // -----------------------------------------------------------------------------
       
  1301 //
       
  1302 void CSecModUIModel::ShowInformationNoteL(
       
  1303     TInt aResourceId,
       
  1304     const TDesC& aString) const
       
  1305     {
       
  1306     LOG_ENTERFN("CSecModUIModel::ShowInformationNoteL()");
       
  1307     HBufC* text = NULL;
       
  1308     if (0 == aString.Length())
       
  1309         {
       
  1310         text = StringLoader::LoadLC(aResourceId);
       
  1311         }
       
  1312     else
       
  1313         {
       
  1314         text = StringLoader::LoadLC(aResourceId, aString);
       
  1315         }
       
  1316     CAknGlobalNote * note = CAknGlobalNote::NewLC();
       
  1317     note->ShowNoteL(EAknGlobalInformationNote, *text);
       
  1318     CleanupStack::PopAndDestroy(2, text);
       
  1319     LOG_LEAVEFN("CSecModUIModel::ShowInformationNoteL()");
       
  1320     }
       
  1321 
       
  1322 // -----------------------------------------------------------------------------
       
  1323 // CSecModUIModel::ActivateTitleL(const TDesC& aTitle) const
       
  1324 // -----------------------------------------------------------------------------
       
  1325 //
       
  1326 void CSecModUIModel::ActivateTitleL(const TDesC& aTitle) const
       
  1327     {
       
  1328     LOG_ENTERFN("CSecModUIModel::ActivateTitleL()");
       
  1329     TUid titlePaneUid;
       
  1330     titlePaneUid.iUid = EEikStatusPaneUidTitle;
       
  1331     CEikStatusPane* sp = iAvkonAppUi->StatusPane();
       
  1332 
       
  1333     CEikStatusPaneBase::TPaneCapabilities subPane =
       
  1334       sp->PaneCapabilities(titlePaneUid);
       
  1335 
       
  1336     if (subPane.IsPresent() && subPane.IsAppOwned())
       
  1337       {
       
  1338       // Fetch pointer to the default title pane control
       
  1339       CAknTitlePane* title = STATIC_CAST(
       
  1340         CAknTitlePane*, sp->ControlL(titlePaneUid) );
       
  1341         title->SetTextL(aTitle);
       
  1342       }
       
  1343     LOG_LEAVEFN("CSecModUIModel::ActivateTitleL()");
       
  1344     }
       
  1345 
       
  1346 // -----------------------------------------------------------------------------
       
  1347 // CSecModUIModel::ActivateTokenLabelToTitleL() const
       
  1348 // -----------------------------------------------------------------------------
       
  1349 //
       
  1350 void CSecModUIModel::ActivateTokenLabelToTitleL() const
       
  1351     {
       
  1352     if (iKeyStore->Token().TokenType().Type().iUid 
       
  1353         == KTokenTypeFileKeystore)
       
  1354         {
       
  1355         HBufC* stringHolder = 
       
  1356             StringLoader::LoadLC(R_QTN_KEYSTORE_TITLE_PHONE_KEYSTORE);
       
  1357         ActivateTitleL(*stringHolder);
       
  1358         CleanupStack::PopAndDestroy(stringHolder);        
       
  1359         }
       
  1360     else
       
  1361         {            
       
  1362         ActivateTitleL(iKeyStore->Token().Label());
       
  1363         }
       
  1364     }
       
  1365 
       
  1366 // -----------------------------------------------------------------------------
       
  1367 // CSecModUIModel::Wrapper()
       
  1368 // -----------------------------------------------------------------------------
       
  1369 //
       
  1370 CSecModUISyncWrapper& CSecModUIModel::Wrapper()
       
  1371     {
       
  1372     return *iWrapper;
       
  1373     }
       
  1374 
       
  1375 // -----------------------------------------------------------------------------
       
  1376 // CSecModUIModel::SecurityModuleCount() const
       
  1377 // -----------------------------------------------------------------------------
       
  1378 //
       
  1379 TInt CSecModUIModel::SecurityModuleCount() const
       
  1380     {
       
  1381     return iAOKeyStores.Count();
       
  1382     }
       
  1383 
       
  1384 //  End of File