connectionutilities/ConnectionDialogs/ConnectionUiUtilities/NotifSrc/WepWpaQueryDlg.cpp
changeset 0 5a93021fdf25
child 1 40cb640ef159
equal deleted inserted replaced
-1:000000000000 0:5a93021fdf25
       
     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:  Implementation of class WepWpaQueryDlg.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <aknnotewrappers.h>
       
    21 #include <StringLoader.h>
       
    22 #include <aknnotedialog.h>
       
    23 #include <ConnUiUtilsNotif.rsg>
       
    24 #include <uikon/eiksrvui.h>
       
    25 
       
    26 #include "WepWpaQueryDlg.h"
       
    27 #include "EasyWepDlgNotif.h"
       
    28 #include "EasyWpaDlgNotif.h"
       
    29 #include "ConnectionDialogsLogger.h"
       
    30 
       
    31 
       
    32 // CONSTANTS
       
    33 #if defined(_DEBUG)
       
    34 _LIT( KErrNullPointer, "NULL pointer" );
       
    35 #endif
       
    36 
       
    37 const TInt KEasyWpaQueryMinLength = 8;
       
    38 const TInt KEasyWpaQueryLengthHEX64 = 64;
       
    39 
       
    40 const TInt KEasyWapiQueryMinLength = 1; 
       
    41 
       
    42 // valid Wep key lengths
       
    43 const TInt KConnUiUtilsWepLengthASCII5 = 5;
       
    44 const TInt KConnUiUtilsWepLengthASCII13 = 13;
       
    45 const TInt KConnUiUtilsWepLengthASCII29 = 29;
       
    46 const TInt KConnUiUtilsWepLengthHEX10 = 10;
       
    47 const TInt KConnUiUtilsWepLengthHEX26 = 26;
       
    48 const TInt KConnUiUtilsWepLengthHEX58 = 58;
       
    49 
       
    50 // ================= MEMBER FUNCTIONS =======================
       
    51 //
       
    52 // ---------------------------------------------------------
       
    53 // CWepWpaQueryDlg::CWepWpaQueryDlg
       
    54 // ---------------------------------------------------------
       
    55 //
       
    56 CWepWpaQueryDlg::CWepWpaQueryDlg( TDes& aDataText, 
       
    57                                   CConnectionDialogsNotifBase* aNotif, 
       
    58                                   TDialogType aDialogType, 
       
    59                                   TBool& aHex )
       
    60 : CAknTextQueryDialog( aDataText ),
       
    61   iNotif( aNotif ), 
       
    62   iDialogType( aDialogType ), 
       
    63   iHex( aHex )
       
    64     {
       
    65     }
       
    66 
       
    67 
       
    68 void CWepWpaQueryDlg::ShowInfoNoteL( TInt aResId )
       
    69     {
       
    70     HBufC* stringLabel = StringLoader::LoadL( aResId, iEikonEnv );
       
    71     CleanupStack::PushL( stringLabel );
       
    72 
       
    73     CAknInformationNote* dialog = new ( ELeave )CAknInformationNote( ETrue );
       
    74     dialog->ExecuteLD( *stringLabel );
       
    75 
       
    76     CleanupStack::PopAndDestroy( stringLabel );   // stringLabel
       
    77     }
       
    78     
       
    79     
       
    80 // ---------------------------------------------------------
       
    81 // CWepWpaQueryDlg::CWepWpaQueryDlg
       
    82 // ---------------------------------------------------------
       
    83 //
       
    84 CWepWpaQueryDlg::~CWepWpaQueryDlg()
       
    85     {
       
    86     STATIC_CAST( CEikServAppUi*, 
       
    87                 CCoeEnv::Static()->AppUi() )->SuppressAppSwitching( EFalse );
       
    88     }
       
    89 
       
    90 
       
    91 // ---------------------------------------------------------
       
    92 // CWepWpaQueryDlg::PreLayoutDynInitL()
       
    93 // ---------------------------------------------------------
       
    94 //
       
    95 void CWepWpaQueryDlg::PreLayoutDynInitL()
       
    96     {
       
    97     
       
    98     CAknTextQueryDialog::PreLayoutDynInitL();
       
    99 
       
   100     STATIC_CAST( CEikServAppUi*, 
       
   101                 CCoeEnv::Static()->AppUi() )->SuppressAppSwitching( ETrue );
       
   102 
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------
       
   106 // CWepWpaQueryDlg::OkToExitL
       
   107 // ---------------------------------------------------------
       
   108 //
       
   109 TBool CWepWpaQueryDlg::OkToExitL( TInt aButtonId )
       
   110     {
       
   111     TBool result = CAknTextQueryDialog::OkToExitL( aButtonId );
       
   112     if ( result )
       
   113         {
       
   114         __ASSERT_DEBUG( iNotif, User::Panic( KErrNullPointer, KErrNone ) );
       
   115         if ( aButtonId == EAknSoftkeyOk )
       
   116             {
       
   117             TInt length = Text().Length();
       
   118             
       
   119             if ( iDialogType == EDialogWpa )
       
   120                 {
       
   121                 if ( length < KEasyWpaQueryMinLength )
       
   122                     {
       
   123                     ShowInfoNoteL( R_INFO_PRESHARED_KEY_TOO_SHORT );
       
   124                     result = EFalse;
       
   125                     
       
   126                     // Wpa only should be cleared
       
   127                     CLOG_WRITE( "Wpa to be cleared!" );
       
   128 
       
   129                     CAknQueryControl* control = QueryControl();
       
   130                     if ( control )
       
   131                         {
       
   132                         control->SetTextL( KNullDesC );
       
   133                         
       
   134                         CCoeControl* coecontrol = 
       
   135                              control->ControlByLayoutOrNull(  EMultiDataFirstEdwin );     
       
   136         
       
   137                         if( coecontrol )
       
   138                             {
       
   139                             CEikEdwin* edwin = static_cast<CEikEdwin*>( coecontrol );
       
   140                             edwin->SetCursorPosL(0, EFalse);	
       
   141                             }
       
   142                         
       
   143                         //control->DrawNow();
       
   144                         }
       
   145                     UpdateLeftSoftKeyL();
       
   146                     }
       
   147                 else if ( length == KEasyWpaQueryLengthHEX64 )
       
   148                     {
       
   149                     TBool foundInvalid = EFalse;
       
   150                     
       
   151                     for ( TInt i = 0; i < length; i++ )
       
   152                         {
       
   153                         if ( ( ( Text()[ i ] < '0' ) || 
       
   154                                ( Text()[ i ] > '9' ) ) &&
       
   155                              ( ( Text()[ i ] < 'A' ) || 
       
   156                                ( Text()[ i ] > 'F' ) ) && 
       
   157                              ( ( Text()[ i ] < 'a' ) || 
       
   158                                ( Text()[ i ] > 'f' ) ) )
       
   159                             {
       
   160                             foundInvalid = ETrue;
       
   161                             break;
       
   162                             }
       
   163                         }
       
   164                     
       
   165                     if ( foundInvalid )
       
   166                         {
       
   167                         ShowInfoNoteL( R_INFO_PRESHARED_KEY_NOT_HEXS );   
       
   168                         result = EFalse;
       
   169                         }
       
   170                     else
       
   171                         {
       
   172                         iNotif->CompleteL( KErrNone );
       
   173                         }
       
   174                     }
       
   175                 else
       
   176                     {
       
   177                     iNotif->CompleteL( KErrNone );
       
   178                     }
       
   179                 }
       
   180             else if ( iDialogType == EDialogWep )// Wep
       
   181                 {
       
   182                 if ( ( length == KConnUiUtilsWepLengthASCII5 ) ||
       
   183                     ( length == KConnUiUtilsWepLengthASCII13 ) ||
       
   184                     ( length == KConnUiUtilsWepLengthASCII29 ) )
       
   185                     {
       
   186                     iHex = EFalse;
       
   187                     iNotif->CompleteL( KErrNone );
       
   188                     }
       
   189                 else if ( ( length == KConnUiUtilsWepLengthHEX10 ) ||
       
   190                     ( length == KConnUiUtilsWepLengthHEX26 ) ||
       
   191                     ( length == KConnUiUtilsWepLengthHEX58 ) )
       
   192                     {
       
   193 
       
   194                     TBool foundInvalid = EFalse;
       
   195                     for ( TInt i = 0; i < length; i++ )
       
   196                         {
       
   197                         if ( ( ( Text()[ i ] < '0' ) || 
       
   198                                ( Text()[ i ] > '9' ) ) &&
       
   199                              ( ( Text()[ i ] < 'A' ) || 
       
   200                                ( Text()[ i ] > 'F' ) ) && 
       
   201                              ( ( Text()[ i ] < 'a' ) || 
       
   202                                ( Text()[ i ] > 'f' ) ) )
       
   203                             {
       
   204                             foundInvalid = ETrue;
       
   205                             break;
       
   206                             }
       
   207                         }
       
   208                     if ( foundInvalid )
       
   209                         {
       
   210                         ShowInfoNoteL( R_INFO_WEP_KEY_ILLEGAL_CHARS );   
       
   211                         result = EFalse;
       
   212                         }
       
   213                     else
       
   214                         {
       
   215                         iHex = ETrue;
       
   216                         iNotif->CompleteL( KErrNone );
       
   217                         }
       
   218                     }
       
   219                 else
       
   220                     {
       
   221                     ShowInfoNoteL( R_INFO_WEP_KEY_INVALID );        
       
   222                     result = EFalse;
       
   223                     }  
       
   224                 }
       
   225             else // Wapi
       
   226                 {
       
   227                 if ( length < KEasyWapiQueryMinLength )
       
   228                     {
       
   229                     ShowInfoNoteL( R_INFO_PRESHARED_KEY_TOO_SHORT );
       
   230                     result = EFalse;
       
   231                     
       
   232                     // Wpa only should be cleared
       
   233                     CLOG_WRITE( "Wapi to be cleared!" );
       
   234 
       
   235                     CAknQueryControl* control = QueryControl();
       
   236                     
       
   237                     if ( control )
       
   238                         {
       
   239                         control->SetTextL( KNullDesC );
       
   240                         
       
   241                         CCoeControl* coecontrol = 
       
   242                              control->ControlByLayoutOrNull(  EMultiDataFirstEdwin );     
       
   243         
       
   244                         if( coecontrol )
       
   245                             {
       
   246                             CEikEdwin* edwin = static_cast<CEikEdwin*>( coecontrol );
       
   247                             edwin->SetCursorPosL(0, EFalse);	
       
   248                             }
       
   249                         
       
   250                         //control->DrawNow();
       
   251                         }
       
   252                     UpdateLeftSoftKeyL();
       
   253                     }
       
   254                 else
       
   255                     {
       
   256                     iNotif->CompleteL( KErrNone );
       
   257                     }    
       
   258                 }    
       
   259             }
       
   260         else
       
   261             {
       
   262             iNotif->CompleteL( KErrCancel );
       
   263             return result;
       
   264             }
       
   265         }
       
   266         
       
   267     CLOG_WRITEF( _L( "result: %d" ), result );
       
   268     CLOG_WRITEF( _L( "iDialogType: %d" ), iDialogType );
       
   269 
       
   270     DrawNow();
       
   271     return result;
       
   272     }
       
   273 
       
   274 // ---------------------------------------------------------
       
   275 // CWepWpaQueryDlg::NeedToDismissQueryL
       
   276 // ---------------------------------------------------------
       
   277 //
       
   278 TBool CWepWpaQueryDlg::NeedToDismissQueryL(const TKeyEvent& aKeyEvent)
       
   279     {
       
   280     if (aKeyEvent.iCode == EKeyPhoneSend)
       
   281         {
       
   282         TryExitL(EEikBidCancel);
       
   283         return ETrue;
       
   284         }
       
   285         
       
   286     return EFalse;
       
   287     }
       
   288 
       
   289 // End of File