Nokia N97 SDK
Example Applications Guide

SIPExAddrQueryDlg.cpp

00001 /*
00002 * ==============================================================================
00003 *  Name        : SIPExAddrQueryDlg.cpp
00004 *  Part of     : SIPEx
00005 *  Interface   : 
00006 *  Description : 
00007 *  Version     : 
00008 *
00009 *  Copyright (c) 2004-2007 Nokia Corporation.
00010 *  This material, including documentation and any related 
00011 *  computer programs, is protected by copyright controlled by 
00012 *  Nokia Corporation.
00013 * ==============================================================================
00014 */
00015 
00016 // INCLUDES
00017 #include "SIPExAddrQueryDlg.h"
00018 #include "SIPEx.hrh"
00019 #include <SIPEx.rsg>
00020 #include <eikenv.h>
00021 #include <avkon.hrh>
00022 #include <stringloader.h>
00023 #include <aknquerycontrol.h>
00024 #include <akndef.h>
00025 #include <Uri8.h>
00026 #include <utf.h>
00027 
00028 // -----------------------------------------------------------------------------
00029 // CSIPExAddrQueryDlg::NewL
00030 // Creates the class instance and returns it.
00031 // -----------------------------------------------------------------------------
00032 //
00033 CSIPExAddrQueryDlg* CSIPExAddrQueryDlg::NewL( TDes& aAddr )
00034     {
00035     CSIPExAddrQueryDlg* self = NewLC( aAddr );
00036     CleanupStack::Pop( self );
00037     return self;
00038     }
00039 
00040 // -----------------------------------------------------------------------------
00041 // CSIPExAddrQueryDlg::NewLC
00042 // Creates the class instance and returns it.
00043 // On return the instance is left to the CleanupStack.
00044 // -----------------------------------------------------------------------------
00045 //
00046 CSIPExAddrQueryDlg* CSIPExAddrQueryDlg::NewLC( TDes& aAddr )
00047     {
00048     CSIPExAddrQueryDlg* self = new (ELeave) CSIPExAddrQueryDlg( aAddr );
00049     CleanupStack::PushL( self );
00050     return self;
00051     }
00052 
00053 // -----------------------------------------------------------------------------
00054 // CSIPExAddrQueryDlg::CSIPExAddrQueryDlg
00055 // C++ default constructor.
00056 // -----------------------------------------------------------------------------
00057 //
00058 CSIPExAddrQueryDlg::CSIPExAddrQueryDlg( TDes& aAddr ) :
00059     iAddress( aAddr )
00060     {
00061     }
00062 
00063 // -----------------------------------------------------------------------------
00064 // CSIPExAddrQueryDlg::~CSIPExAddrQueryDlg
00065 // Desctructor.
00066 // -----------------------------------------------------------------------------
00067 //
00068 CSIPExAddrQueryDlg::~CSIPExAddrQueryDlg()
00069     {
00070     }
00071 
00072 // -----------------------------------------------------------------------------
00073 // CSIPExAddrQueryDlg::PreLayoutDynInitL
00074 // From CEikDialog. Initializes the dialog's text control with default address
00075 // if available.
00076 // -----------------------------------------------------------------------------
00077 //
00078 void CSIPExAddrQueryDlg::PreLayoutDynInitL()
00079     {
00080     // first we have to execute PreLayoutDynInitL() of the base-class
00081     CAknQueryDialog::PreLayoutDynInitL();
00082     if ( iAddress.Length() > 0 )
00083         {
00084         static_cast< CAknQueryControl* >( 
00085             Control( ESIPExInviteAddressId ) )->SetTextL( iAddress );
00086         }
00087     }
00088 
00089 // -----------------------------------------------------------------------------
00090 // CSIPExAddrQueryDlg::OkToExitL
00091 // From CEikDialog.
00092 // Validates the given address and if not correct notifies user with info
00093 // message.
00094 // -----------------------------------------------------------------------------
00095 //
00096 TBool CSIPExAddrQueryDlg::OkToExitL( TInt aKeyCode )
00097     {
00098     TBool isOk( ETrue );
00099     
00100     if ( aKeyCode == EAknSoftkeyOk )
00101         {  
00102         static_cast< CAknQueryControl* >( 
00103                 Control( ESIPExInviteAddressId ) )->GetText( iAddress );
00104 
00105         // Check the validity of the given address
00106         HBufC8* address = HBufC8::NewLC( iAddress.Length() );
00107         TPtr8 paddress( address->Des() );
00108         CnvUtfConverter::ConvertFromUnicodeToUtf8( paddress, iAddress );
00109         
00110         if ( !AddressValid( paddress ) )
00111             {
00112             HBufC* txt = StringLoader::LoadLC( R_ERROR_IN_ADDRESS_TXT );
00113             CEikonEnv::Static()->InfoMsg( txt->Des() );
00114             CleanupStack::PopAndDestroy( txt );
00115             isOk = EFalse;
00116             }
00117         
00118         CleanupStack::PopAndDestroy( address );
00119         }
00120 
00121     return isOk;
00122     }
00123 
00124 // -----------------------------------------------------------------------------
00125 // CSIPExAddrQueryDlg::AddressValid
00126 // Checks if user typed address is valid sip address.
00127 // -----------------------------------------------------------------------------
00128 //    
00129 TBool CSIPExAddrQueryDlg::AddressValid( const TDesC8& aSipAddr )
00130     {
00131     _LIT8( KTypeSIP, "sip" );
00132     
00133     TUriParser8 parser;
00134     User::LeaveIfError( parser.Parse( aSipAddr ) ); 
00135     CUri8* uri8 = CUri8::NewLC( parser );
00136     
00137     TBool valid( ETrue );
00138     
00139     if ( uri8->Uri().Extract( EUriScheme ).CompareF( KTypeSIP() ) != KErrNone )
00140         {
00141         valid = EFalse;
00142         }
00143     if ( uri8->Uri().Extract( EUriUserinfo ) == KNullDesC8 )
00144         {
00145         valid = EFalse;
00146         }
00147     if ( uri8->Uri().Extract( EUriHost ) == KNullDesC8 )
00148         {
00149         valid = EFalse;
00150         }
00151     CleanupStack::PopAndDestroy( uri8 );
00152         
00153     return valid;        
00154     }
00155 
00156 // End of file

© Nokia 2009

Back to top