realtimenetprots/sipfw/SampleApp/gameUI_techview/Src/SIPExAddrQueryDlg.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 
       
     2 // Copyright (c) 2004-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:
       
    15 //
       
    16 
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include    "SIPExAddrQueryDlg.h"
       
    21 #include    "SIPEx.hrh"
       
    22 #include    <sipex.rsg>
       
    23 #include    <eikenv.h>
       
    24 #include    <uri8.h>
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CSIPExAddrQueryDlg::NewL
       
    28 // Creates the class instance and returns it.
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 CSIPExAddrQueryDlg* CSIPExAddrQueryDlg::NewL( TDes& aAddr )
       
    32     {
       
    33     CSIPExAddrQueryDlg* self = NewLC( aAddr );
       
    34     CleanupStack::Pop( self );
       
    35     return self;
       
    36     }
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CSIPExAddrQueryDlg::NewLC
       
    40 // Creates the class instance and returns it.
       
    41 // On return the instance is left to the CleanupStack.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CSIPExAddrQueryDlg* CSIPExAddrQueryDlg::NewLC( TDes& aAddr )
       
    45     {
       
    46     CSIPExAddrQueryDlg* self = new (ELeave) CSIPExAddrQueryDlg( aAddr );
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL();
       
    49     return self;
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CSIPExAddrQueryDlg::CSIPExAddrQueryDlg
       
    54 // C++ default constructor.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CSIPExAddrQueryDlg::CSIPExAddrQueryDlg( TDes& aAddr )
       
    58     : iAddress( aAddr )
       
    59     {
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CSIPExAddrQueryDlg::~CSIPExAddrQueryDlg
       
    64 // Desctructor.
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CSIPExAddrQueryDlg::~CSIPExAddrQueryDlg()
       
    68     {
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CSIPExAddrQueryDlg::ConstructL
       
    73 // Symbian 2nd phase constructor that might leave.
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 void CSIPExAddrQueryDlg::ConstructL()
       
    77     {
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CSIPExAddrQueryDlg::PreLayoutDynInitL
       
    82 // From CEikDialog. Initializes the dialog's text control with default address
       
    83 // if available.
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 void CSIPExAddrQueryDlg::PreLayoutDynInitL()
       
    87     {
       
    88     if ( iAddress.Length() > 0 )
       
    89         {
       
    90         ( static_cast<CEikEdwin*>( 
       
    91             Control( ESIPExInviteAddressId ) ) )->SetTextL( &iAddress );
       
    92         }
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CSIPExAddrQueryDlg::OkToExitL
       
    97 // From CEikDialog.
       
    98 // Validates the given address and if not correct notifies user with info
       
    99 // message.
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 TBool CSIPExAddrQueryDlg::OkToExitL( TInt aKeyCode )
       
   103     {
       
   104     TBool isOk( ETrue );
       
   105     
       
   106     if ( aKeyCode == EEikBidOk )
       
   107         {
       
   108         ( static_cast< CEikEdwin* >( 
       
   109             Control( ESIPExInviteAddressId ) ) )->GetText( iAddress );
       
   110 
       
   111         // Check the validity of the given address
       
   112         TInt err( KErrGeneral );
       
   113         
       
   114         HBufC8* address = HBufC8::NewLC( iAddress.Length() );
       
   115         address->Des().Copy( iAddress );
       
   116         
       
   117         if ( !AddressValid( *address ) )
       
   118             {
       
   119             HBufC* txt = 
       
   120                     iEikonEnv->AllocReadResourceLC( R_ERROR_IN_ADDRESS_TXT );
       
   121             CEikonEnv::Static()->InfoMsg( txt->Des() );
       
   122             CleanupStack::PopAndDestroy( txt );
       
   123             isOk = EFalse;
       
   124             }
       
   125         
       
   126         CleanupStack::PopAndDestroy( address );
       
   127         }
       
   128 
       
   129     return isOk;
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CSIPExAddrQueryDlg::AddressValid
       
   134 // Checks if user typed address is valid sip address.
       
   135 // -----------------------------------------------------------------------------
       
   136 //    
       
   137 TBool CSIPExAddrQueryDlg::AddressValid( const TDesC8& aSipAddr )
       
   138     {
       
   139     _LIT8( KTypeSIP, "sip" );
       
   140     
       
   141     TUriParser8 parser;
       
   142     User::LeaveIfError( parser.Parse( aSipAddr ) ); 
       
   143     CUri8* uri8 = CUri8::NewLC( parser );
       
   144     
       
   145     TBool valid( ETrue );
       
   146     
       
   147     if ( uri8->Uri().Extract( EUriScheme ).CompareF( KTypeSIP() ) != KErrNone )
       
   148         {
       
   149         valid = EFalse;
       
   150         }
       
   151     if ( uri8->Uri().Extract( EUriUserinfo ) == KNullDesC8 )
       
   152         {
       
   153         valid = EFalse;
       
   154         }
       
   155     if ( uri8->Uri().Extract( EUriHost ) == KNullDesC8 )
       
   156         {
       
   157         valid = EFalse;
       
   158         }
       
   159     CleanupStack::PopAndDestroy( uri8 );
       
   160         
       
   161     return valid;        
       
   162     }
       
   163 
       
   164 // End of file