deviceencryption/DevEncNotifPlugin/src/DevEncPasswdDlg.cpp
branchRCL_3
changeset 38 491b3ed49290
parent 36 95243422089a
child 39 65326cf895ed
equal deleted inserted replaced
36:95243422089a 38:491b3ed49290
     1 /*
       
     2 * Copyright (c) 2005 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:  CDevEncPasswdDlg implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "DevEncPasswdDlg.h"
       
    19 #include "DevEncUids.hrh"
       
    20 #include "DevEncDef.h"
       
    21 #include <eiksrvui.h>
       
    22 #include <devencnotifplugin.rsg>
       
    23 #include <StringLoader.h>
       
    24 #include <bautils.h>         // BAFL utils (for language file)
       
    25 #include <data_caging_path_literals.hrh>
       
    26 #include <utf.h>
       
    27 #include "DevEncLog.h"
       
    28 
       
    29 #define KErrorNoteTimeout   2000000
       
    30 _LIT(KFileDrive,"z:");
       
    31 _LIT(KResourceFileName, "DevEncNotifPlugin.rsc");
       
    32 
       
    33 CDevEncPasswdDlg::CDevEncPasswdDlg() : 
       
    34     CActive( EPriorityStandard ),	// Standard priority
       
    35     iNeedToCompleteMessage( EFalse )
       
    36     {
       
    37     }
       
    38 
       
    39 CDevEncPasswdDlg* CDevEncPasswdDlg::NewLC()
       
    40     {
       
    41 	CDevEncPasswdDlg* self = new ( ELeave ) CDevEncPasswdDlg();
       
    42 	CleanupStack::PushL( self );
       
    43 	self->ConstructL();
       
    44 	return self;
       
    45     }
       
    46 
       
    47 CDevEncPasswdDlg* CDevEncPasswdDlg::NewL()
       
    48     {
       
    49 	CDevEncPasswdDlg* self = CDevEncPasswdDlg::NewLC();
       
    50 	CleanupStack::Pop(); // self;
       
    51 	return self;
       
    52     }
       
    53 
       
    54 void CDevEncPasswdDlg::ConstructL()
       
    55     {
       
    56     DFLOG( "CDevEncPasswdDlg::ConstructL Begin" );
       
    57 	CActiveScheduler::Add( this );				// Add to scheduler
       
    58     
       
    59     iEikEnv = CEikonEnv::Static();
       
    60     iTimer.CreateLocal();
       
    61     TFileName filename;
       
    62     filename += KFileDrive;
       
    63     filename += KDC_RESOURCE_FILES_DIR; // From data_caging_path_literals.hrh
       
    64     filename += KResourceFileName;
       
    65     BaflUtils::NearestLanguageFile( iEikEnv->FsSession(), filename );
       
    66     iResourceFileFlag = iEikEnv->AddResourceFileL( filename );
       
    67     DFLOG( "CDevEncPasswdDlg::ConstructL End" );
       
    68     }
       
    69 
       
    70 CDevEncPasswdDlg::~CDevEncPasswdDlg()
       
    71     {
       
    72     DFLOG( "CDevEncPasswdDlg::~CDevEncPasswdDlg Begin" );
       
    73     Cancel();
       
    74     iEikEnv->DeleteResourceFile( iResourceFileFlag );
       
    75     if ( iNeedToCompleteMessage )
       
    76         {
       
    77         iMessage.Complete( KErrDied );
       
    78         }
       
    79     iTimer.Close();
       
    80     DFLOG( "CDevEncPasswdDlg::~CDevEncPasswdDlg End" );
       
    81     }
       
    82 
       
    83 void CDevEncPasswdDlg::DoCancel()
       
    84     {
       
    85 
       
    86     }
       
    87 
       
    88 void CDevEncPasswdDlg::Release()
       
    89     {
       
    90     delete this;  
       
    91     }
       
    92    
       
    93 CDevEncPasswdDlg::TNotifierInfo CDevEncPasswdDlg::RegisterL()
       
    94     {
       
    95     DFLOG( "CDevEncPasswdDlg::RegisterL Begin" );
       
    96     iInfo.iUid = TUid::Uid( KDevEncPasswdDlgUid );
       
    97     iInfo.iChannel = TUid::Uid( KDevEncPasswdDlgUid );
       
    98     iInfo.iPriority = ENotifierPriorityVHigh;
       
    99     DFLOG( "CDevEncPasswdDlg::RegisterL End" );
       
   100     return iInfo;
       
   101     }
       
   102 
       
   103 CDevEncPasswdDlg::TNotifierInfo CDevEncPasswdDlg::Info() const
       
   104     {
       
   105     return iInfo;
       
   106     }
       
   107 
       
   108 TPtrC8 CDevEncPasswdDlg::StartL(const TDesC8& /*aBuffer*/)
       
   109     {
       
   110     return TPtrC8();
       
   111     }
       
   112 
       
   113 void CDevEncPasswdDlg::StartL(const TDesC8& /*aBuffer*/, TInt aReplySlot, const RMessagePtr2& aMessage)
       
   114     {
       
   115     DFLOG( "CDevEncPasswdDlg::StartL Begin" );
       
   116     iMessage = aMessage;
       
   117     iReplySlot = aReplySlot;
       
   118     iNeedToCompleteMessage = ETrue;
       
   119     
       
   120     SetActive();
       
   121     iStatus = KRequestPending;
       
   122     TRequestStatus* stat = &iStatus;
       
   123     User::RequestComplete( stat, KErrNone );
       
   124     DFLOG( "CDevEncPasswdDlg::StartL End" );
       
   125     }
       
   126 
       
   127 void CDevEncPasswdDlg::Cancel()
       
   128     {
       
   129     CActive::Cancel();
       
   130     }
       
   131 
       
   132 TPtrC8 CDevEncPasswdDlg::UpdateL(const TDesC8& /*aBuffer*/)
       
   133     {
       
   134     return TPtrC8();    
       
   135     }
       
   136    
       
   137    
       
   138 void CDevEncPasswdDlg::RunL()
       
   139     {
       
   140     DFLOG( "CDevEncPasswdDlg::RunL Begin" );
       
   141     TBuf<KMaxPasswordLength> passwdIn;
       
   142     TBuf8<KMaxPasswordLength> passwdOut;
       
   143 
       
   144     STATIC_CAST( CEikServAppUi*, iEikEnv->AppUi())->
       
   145         SuppressAppSwitching( ETrue );
       
   146     
       
   147     iDlg = CAknTextQueryDialog::NewL( passwdIn );
       
   148     iDlg->SetMaxLength( KMaxPasswordLength );
       
   149     DFLOG( "CDevEncPasswdDlg: PasswdDlg: ExecuteLD" );
       
   150     TInt resp = iDlg->ExecuteLD( R_DEVENC_PASSWD_QUERY );
       
   151     iDlg = NULL;
       
   152     
       
   153     if ( resp == EEikBidCancel )
       
   154         {
       
   155         iMessage.Complete( KErrCancel );        
       
   156         iNeedToCompleteMessage = EFalse;
       
   157         }
       
   158     else
       
   159         {
       
   160         if ( CnvUtfConverter::ConvertFromUnicodeToUtf8( passwdOut, passwdIn ) )
       
   161             {
       
   162             iNote = new (ELeave) CAknErrorNote();
       
   163             HBufC* prompt = StringLoader::LoadLC( R_DEVENC_INVALID_PASSWD_STRING );
       
   164             iNote->ExecuteLD( *prompt );
       
   165             iNote = NULL;
       
   166             CleanupStack::PopAndDestroy( prompt );
       
   167 
       
   168             iTimer.After( iStatus, KErrorNoteTimeout );
       
   169             SetActive();
       
   170             return;
       
   171             }
       
   172         else
       
   173             {
       
   174             iMessage.WriteL( iReplySlot, passwdOut );
       
   175             iMessage.Complete( KErrNone );            
       
   176             iNeedToCompleteMessage = EFalse;
       
   177             }
       
   178         }
       
   179     STATIC_CAST( CEikServAppUi*, iEikEnv->AppUi())->
       
   180         SuppressAppSwitching( EFalse );
       
   181     DFLOG( "CDevEncPasswdDlg::RunL End" );
       
   182     }
       
   183 
       
   184 TInt CDevEncPasswdDlg::RunError( TInt aError )
       
   185     {
       
   186     if( iNeedToCompleteMessage )
       
   187         {
       
   188         iMessage.Complete( aError );
       
   189         }
       
   190         
       
   191     iNeedToCompleteMessage = EFalse;
       
   192     iReplySlot = NULL;
       
   193     STATIC_CAST( CEikServAppUi*, iEikEnv->AppUi())->
       
   194         SuppressAppSwitching( EFalse );
       
   195 
       
   196 	return aError;
       
   197     }
       
   198 
       
   199 // End of file
       
   200