wlansecuritysettings/wlaneapsettingsui/EapGtc/NotifierUi/src/GtcNotifDlgPlugin.cpp
changeset 0 c8830336c852
child 2 1c7bc153c08e
equal deleted inserted replaced
-1:000000000000 0:c8830336c852
       
     1 /*
       
     2 * Copyright (c) 2001-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 the License "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 GtcNotif dialog plugin.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <coemain.h>
       
    22 #include <eikenv.h>
       
    23 #include <bautils.h>
       
    24 #include <data_caging_path_literals.hrh>
       
    25 #include <GtcNotifDlgUi.rsg>
       
    26 #include <e32base.h>
       
    27 #include <StringLoader.h>
       
    28 
       
    29 #include <e32property.h>            // For RProperty 
       
    30 #include <UikonInternalPSKeys.h>    // For KPSUidUikon and KUikGlobalNotesAllowed.
       
    31 
       
    32 #include "GtcNotifDlgPlugin.h"
       
    33 #include "GTCResponseQueryDialog.h"
       
    34 #include "GTCMessageDisplayDialog.h"
       
    35 
       
    36 
       
    37 // CONSTANTS
       
    38 static const TInt KMaxLengthOfGtcResponse = 256;
       
    39 
       
    40 // Ratio between ascii and unicode character sizes
       
    41 static const TUint KAsciiUnicodeRatio = 2;
       
    42 
       
    43 
       
    44 
       
    45 // ================= OTHER EXPORTED FUNCTIONS ==============
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CreateNotifiersL
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 LOCAL_C void CreateNotifiersL( 
       
    52                           CArrayPtrFlat< MEikSrvNotifierBase2 >* aNotifiers )
       
    53     {
       
    54     MEikSrvNotifierBase2 *serNotify;
       
    55 
       
    56     serNotify = CGtcDialogPlugin::NewL();
       
    57     CleanupStack::PushL( serNotify );
       
    58     aNotifiers->AppendL( serNotify );
       
    59     CleanupStack::Pop( serNotify );
       
    60     }
       
    61 
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // NotifierArray
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 EXPORT_C CArrayPtr< MEikSrvNotifierBase2 >* NotifierArray()
       
    68     {
       
    69     // NotifierArray() can't leave
       
    70     CArrayPtrFlat< MEikSrvNotifierBase2 >* array = 
       
    71             new CArrayPtrFlat< MEikSrvNotifierBase2 >( KPluginGranularity );
       
    72 
       
    73     if ( array )
       
    74         {
       
    75         TRAPD( err, CreateNotifiersL( array ) );
       
    76         
       
    77         if( err )
       
    78             {
       
    79             TInt count = array->Count();
       
    80 
       
    81             while( count-- )
       
    82                 {
       
    83                 ( *array )[ count ]->Release();
       
    84                 }
       
    85 
       
    86             delete array;
       
    87             array = NULL;
       
    88             }
       
    89         }
       
    90 
       
    91     return( array );
       
    92     }
       
    93 
       
    94 
       
    95 //////////////////////////////////////////////////////////////
       
    96 // Gtc dialog plugin
       
    97 /////////////////////////////////////////////////////////////
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CGtcDialogPlugin::CGtcDialogPlugin
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 CGtcDialogPlugin::CGtcDialogPlugin()
       
   104 : iCancelled( EFalse ), 
       
   105   iGtcMessageCancelled( EFalse )
       
   106     {
       
   107     iManager = NULL;
       
   108     }
       
   109 
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CGtcDialogPlugin::~CGtcDialogPlugin
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 CGtcDialogPlugin::~CGtcDialogPlugin()
       
   116     {
       
   117     CCoeEnv::Static()->DeleteResourceFile( iResource );
       
   118 
       
   119     if ( !iGtcMessageCancelled )
       
   120         {
       
   121         delete iGTCMessageDisplayDlg;
       
   122         }
       
   123 
       
   124     if ( !iCancelled )
       
   125         {
       
   126         delete iGTCResponseQueryDlg;
       
   127         }
       
   128     }
       
   129 
       
   130 
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CGtcDialogPlugin::RegisterL
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 CGtcDialogPlugin::TNotifierInfo CGtcDialogPlugin::RegisterL()
       
   137     {
       
   138     iInfo.iUid      = KUidGtcDialog;
       
   139     iInfo.iPriority = ENotifierPriorityHigh;
       
   140     iInfo.iChannel  = KUidGtcDialog;
       
   141     return iInfo;
       
   142     }
       
   143 
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CGtcDialogPlugin::NewL
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 CGtcDialogPlugin* CGtcDialogPlugin::NewL()
       
   150     {
       
   151     CGtcDialogPlugin* self = new ( ELeave ) CGtcDialogPlugin();
       
   152     CleanupStack::PushL( self );
       
   153     self->ConstructL();
       
   154     CleanupStack::Pop( self );
       
   155     return self;
       
   156     }
       
   157 
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CGtcDialogPlugin::ConstructL
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 void CGtcDialogPlugin::ConstructL()
       
   164     {
       
   165     TFileName fileName;
       
   166 
       
   167     fileName.Append( KDriveZ );
       
   168     fileName.Append( KDC_RESOURCE_FILES_DIR );
       
   169     fileName.Append( KResourceFileName );
       
   170 
       
   171     BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), fileName );
       
   172     iResource = CCoeEnv::Static()->AddResourceFileL( fileName );
       
   173     }
       
   174 
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CGtcDialogPlugin::StartL
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 TPtrC8 CGtcDialogPlugin::StartL( const TDesC8& /*aBuffer*/ )
       
   181     {
       
   182     return KNullDesC8().Ptr();
       
   183     }
       
   184 
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CGtcDialogPlugin::StartL
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 void CGtcDialogPlugin::StartL( const TDesC8&  aBuffer, 
       
   191                                TInt aReplySlot, 
       
   192                                const RMessagePtr2& aMessage )
       
   193     {
       
   194     iCancelled = EFalse;
       
   195     iReplySlot = aReplySlot;
       
   196     iMessage   = aMessage;
       
   197      
       
   198     // This object gets constructed only once where as this gets called many 
       
   199     // times, if user is not answering the query. 
       
   200     // So initialize everything here itself.
       
   201     iGTCResponseQueryDlg = NULL;
       
   202     iGTCMessageDisplayDlg = NULL;
       
   203     iDataPtr = NULL;
       
   204     iDataPckgPtr = NULL;
       
   205     iGtcMessageCancelled = EFalse;
       
   206 
       
   207     // We are about to display the password prompt.
       
   208     // Since this part of the code can be executed during the bootup, check if
       
   209     // the UI has really started up to display notes/dialogs.
       
   210     TInt notesAllowed = 0;
       
   211     TInt error = RProperty::Get( KPSUidUikon, KUikGlobalNotesAllowed, 
       
   212                                  notesAllowed );
       
   213 
       
   214     // The above call can return error. Don't care the error. What we care is
       
   215     // if notesAllowed has turned to 1 from 0.
       
   216     if ( notesAllowed )
       
   217         {
       
   218         // Display EAP-GTC message if there's one...
       
   219         if ( aBuffer.Length() != 0 )
       
   220             {
       
   221             HBufC16* buffer = HBufC16::NewLC( aBuffer.Size() /
       
   222                                                         KAsciiUnicodeRatio );
       
   223             TPtr16 text = buffer->Des();
       
   224             text.Copy( reinterpret_cast<TUint16 *>( const_cast<TUint8 *> (
       
   225                                         aBuffer.Ptr() ) ), aBuffer.Size() /
       
   226                                                         KAsciiUnicodeRatio );
       
   227 
       
   228             iGTCMessageDisplayDlg = CGTCMessageDisplayDialog::NewL( text, 
       
   229                                                                     this );
       
   230             iGTCMessageDisplayDlg->ExecuteLD( R_MESSAGE_QUERY );
       
   231 
       
   232             // Do not set iGTCMessageDisplayDlg to NULL here, because then
       
   233             // a timeout cancel will cause a crash. Prevent double deletion
       
   234             // by checking iGtcMessageCancelled in the destructor.
       
   235 
       
   236             CleanupStack::PopAndDestroy( buffer );
       
   237             }
       
   238         else
       
   239             {
       
   240             // Show the data query directly since there is no message to display.
       
   241             CompleteMessageDisplayL( KErrNone );
       
   242             }
       
   243         }
       
   244 
       
   245     // In case if the notes are not allowed, this message gets completed when 
       
   246     // EAPOL time out occurs and a subsequent call to cancel from 
       
   247     // eap_am_type_securid_symbian_c::DoCancel().
       
   248 
       
   249     }
       
   250 
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // CGtcDialogPlugin::UpdateL
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 TPtrC8 CGtcDialogPlugin::UpdateL( const TDesC8& /*aBuffer*/ )
       
   257     {
       
   258     return KNullDesC8().Ptr();
       
   259     }
       
   260 
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // CGtcDialogPlugin::Cancel
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266 void CGtcDialogPlugin::Cancel()
       
   267     {
       
   268     if ( !iCancelled )
       
   269         {
       
   270         iCancelled = ETrue;
       
   271 
       
   272         if ( !iMessage.IsNull() )
       
   273             {
       
   274             iMessage.Complete( KErrCancel );
       
   275             }
       
   276 
       
   277         if ( iGTCResponseQueryDlg )
       
   278             {
       
   279             delete iGTCResponseQueryDlg;
       
   280             iGTCResponseQueryDlg = NULL;
       
   281             }
       
   282 
       
   283         if ( !iGtcMessageCancelled && iGTCMessageDisplayDlg )
       
   284             {
       
   285             iGtcMessageCancelled = ETrue;
       
   286             delete iGTCMessageDisplayDlg;
       
   287             iGTCMessageDisplayDlg = NULL;
       
   288             }
       
   289         }
       
   290 
       
   291     if( iDataPtr ) 
       
   292         {
       
   293         delete iDataPtr;
       
   294         iDataPtr = NULL;
       
   295         }
       
   296 
       
   297     if( iDataPckgPtr ) 
       
   298         {
       
   299         delete iDataPckgPtr;
       
   300         iDataPckgPtr = NULL;
       
   301         }
       
   302     }
       
   303 
       
   304 
       
   305 // -----------------------------------------------------------------------------
       
   306 // CGtcDialogPlugin::CompleteL
       
   307 // -----------------------------------------------------------------------------
       
   308 //
       
   309 void CGtcDialogPlugin::CompleteL( TInt aStatus )
       
   310     { 
       
   311     if ( aStatus == KErrNone  && !iMessage.IsNull() )
       
   312         {
       
   313         iMessage.WriteL( iReplySlot, *iDataPckgPtr);
       
   314         }
       
   315 
       
   316     iCancelled = ETrue;
       
   317     
       
   318     if ( !iMessage.IsNull() )
       
   319         {
       
   320         iMessage.Complete( aStatus );
       
   321         }
       
   322 
       
   323     if( iDataPtr ) 
       
   324         {
       
   325         delete iDataPtr;
       
   326         iDataPtr = NULL;
       
   327     }
       
   328 
       
   329     if( iDataPckgPtr ) 
       
   330         {
       
   331         delete iDataPckgPtr;
       
   332         iDataPckgPtr = NULL;
       
   333         }
       
   334     }
       
   335 
       
   336 
       
   337 // -----------------------------------------------------------------------------
       
   338 // CGtcDialogPlugin::Release
       
   339 // -----------------------------------------------------------------------------
       
   340 //
       
   341 void CGtcDialogPlugin::Release()
       
   342     {
       
   343     delete this;
       
   344     }
       
   345 
       
   346 
       
   347 // -----------------------------------------------------------------------------
       
   348 // CGtcDialogPlugin::Info
       
   349 // -----------------------------------------------------------------------------
       
   350 //
       
   351 CGtcDialogPlugin::TNotifierInfo CGtcDialogPlugin::Info() const
       
   352     {
       
   353     return iInfo;
       
   354     }
       
   355 
       
   356 
       
   357 // -----------------------------------------------------------------------------
       
   358 // CGtcDialogPlugin::CompleteMessageDisplayL
       
   359 // -----------------------------------------------------------------------------
       
   360 //
       
   361 void CGtcDialogPlugin::CompleteMessageDisplayL( TInt aStatus )
       
   362     {
       
   363     iGtcMessageCancelled = ETrue;
       
   364 
       
   365     if ( aStatus == KErrNone )
       
   366         {
       
   367         // Now user has acknowledged the GTC message.
       
   368         // Show the response query to enter the password.
       
   369 
       
   370         iDataPtr = new( ELeave ) TEapGtcUsernamePasswordInfo;
       
   371         iDataPckgPtr = new( ELeave ) TPckg<TEapGtcUsernamePasswordInfo>( 
       
   372                                                                 *iDataPtr );
       
   373 
       
   374         TBuf16<KMaxLengthOfGtcResponse> response;
       
   375 
       
   376         iGTCResponseQueryDlg = CGTCResponseQueryDialog::NewL( 
       
   377                                                 iDataPtr->iPasscode, this );
       
   378 
       
   379         HBufC* text = StringLoader::LoadLC( R_GTC_RESPONSE );
       
   380         iGTCResponseQueryDlg->SetPromptL( *text );
       
   381         CleanupStack::PopAndDestroy( text );
       
   382 
       
   383         iGTCResponseQueryDlg->ExecuteLD( R_GTC_PASSWORD_QUERY);
       
   384 
       
   385         // Do not set iGTCResponseQueryDlg to NULL here, because then
       
   386         // a timeout cancel will cause a crash. Prevent double deletion
       
   387         // by checking iCancelled in the destructor.
       
   388         }
       
   389     else
       
   390         {
       
   391         // User probably cancelled the message, some how.
       
   392         // Can not continue to show the password query.
       
   393         if ( !iMessage.IsNull() )
       
   394             {
       
   395             iMessage.Complete( aStatus );
       
   396             }
       
   397         }
       
   398     }
       
   399 
       
   400 
       
   401 // End of File