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