Nokia N97 SDK
Example Applications Guide

SIPExIMDialog.cpp

00001 /*
00002 * ==============================================================================
00003 *  Name        : CSIPExIMDialog.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 "SIPExIMDialog.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 // CSIPExIMDialog::NewL
00030 // Static constructor
00031 // -----------------------------------------------------------------------------
00032 //
00033 CSIPExIMDialog* CSIPExIMDialog::NewL( TDes& aAddress, TDes& aMsg )
00034     {
00035     CSIPExIMDialog* self = NewLC( aAddress, aMsg );
00036     CleanupStack::Pop(self);
00037     return self;
00038     }
00039 
00040 // -----------------------------------------------------------------------------
00041 // CSIPExIMDialog::NewLC
00042 // Static constructor. On return the instance is left to the CleanupStack.
00043 // -----------------------------------------------------------------------------
00044 //
00045 CSIPExIMDialog* CSIPExIMDialog::NewLC( TDes& aAddress, TDes& aMsg )
00046     {
00047     CSIPExIMDialog* self = new (ELeave) CSIPExIMDialog( aAddress, aMsg );
00048     CleanupStack::PushL(self);
00049     self->ConstructL();
00050     return self;
00051     }
00052 
00053 // -----------------------------------------------------------------------------
00054 // CSIPExIMDialog::CSIPExIMDialog
00055 // C++ default constructor. Initializes the member variables with default values
00056 // from client.
00057 // -----------------------------------------------------------------------------
00058 //
00059 CSIPExIMDialog::CSIPExIMDialog( TDes& aAddress, TDes& aMsg )
00060   : CAknMultiLineDataQueryDialog( ENoTone )
00061   , iAddress( aAddress ), iMsg( aMsg )
00062     {
00063     }
00064 
00065 // -----------------------------------------------------------------------------
00066 // CSIPExIMDialog::~CSIPExIMDialog
00067 // Destructor
00068 // -----------------------------------------------------------------------------
00069 //
00070 CSIPExIMDialog::~CSIPExIMDialog()
00071     {
00072     }
00073 
00074 // -----------------------------------------------------------------------------
00075 // CSIPExIMDialog::ConstructL
00076 // Symbian 2nd phase constructor that might leave.
00077 // -----------------------------------------------------------------------------
00078 //
00079 void CSIPExIMDialog::ConstructL()
00080     {
00081         SetDataL( iAddress, iMsg );
00082     }
00083 
00084 // -----------------------------------------------------------------------------
00085 // CSIPExIMDialog::PreLayoutDynInitL
00086 // From CEikDialog. Called before drawing the dialog.
00087 // If address variable has used earlier use that value as default.
00088 // -----------------------------------------------------------------------------
00089 //
00090 void CSIPExIMDialog::PreLayoutDynInitL()
00091     {
00092     // first we have to execute PreLayoutDynInitL() of the base-class
00093     CAknMultiLineDataQueryDialog::PreLayoutDynInitL();
00094     if( iAddress.Length() > 0 )
00095         {
00096         FirstControl()->SetTextL( iAddress );
00097         }
00098     }
00099 
00100 // -----------------------------------------------------------------------------
00101 // CSIPExIMDialog::OkToExitL
00102 // From CEikDialog. Called when user presses dialog's button.
00103 // Validates the given address and if not correct notifies user with info
00104 // message. The length of the message is limited in resource file to 256.
00105 // The limitation is not in SIP implementation.
00106 // -----------------------------------------------------------------------------
00107 //
00108 TBool CSIPExIMDialog::OkToExitL(TInt aKeyCode)
00109     {   
00110     TBool isOk( ETrue );
00111     
00112     if( aKeyCode == EAknSoftkeyOk )
00113         {
00114         FirstControl()->GetText( iAddress );
00115         SecondControl()->GetText( iMsg );
00116 
00117         // Check the validity of the given address
00118         HBufC8* address = HBufC8::NewLC( iAddress.Length() );
00119         TPtr8 paddress( address->Des() );
00120         CnvUtfConverter::ConvertFromUnicodeToUtf8( paddress, iAddress );
00121         
00122         if ( !AddressValid( paddress ) )
00123             {
00124             HBufC* txt = StringLoader::LoadLC( R_ERROR_IN_ADDRESS_TXT );
00125             CEikonEnv::Static()->InfoMsg( txt->Des() );
00126             CleanupStack::PopAndDestroy( txt );
00127             isOk = EFalse;
00128             }
00129                
00130         CleanupStack::PopAndDestroy( address );
00131         }
00132 
00133     return isOk;
00134     }
00135 
00136 
00137 // -----------------------------------------------------------------------------
00138 // CSIPExIMDialog::AddressValid
00139 // Checks if user typed address is valid sip address.
00140 // -----------------------------------------------------------------------------
00141 //    
00142 TBool CSIPExIMDialog::AddressValid( const TDesC8& aSipAddr )
00143     {
00144     _LIT8( KTypeSIP, "sip" );
00145     
00146     TUriParser8 parser;
00147     User::LeaveIfError( parser.Parse( aSipAddr ) ); 
00148     CUri8* uri8 = CUri8::NewLC( parser );
00149     
00150     TBool valid( ETrue );
00151     
00152     if ( uri8->Uri().Extract( EUriScheme ).CompareF( KTypeSIP() ) != KErrNone )
00153         {
00154         valid = EFalse;
00155         }
00156     if ( uri8->Uri().Extract( EUriUserinfo ) == KNullDesC8 )
00157         {
00158         valid = EFalse;
00159         }
00160     if ( uri8->Uri().Extract( EUriHost ) == KNullDesC8 )
00161         {
00162         valid = EFalse;
00163         }
00164     CleanupStack::PopAndDestroy( uri8 );
00165         
00166     return valid;           
00167     }
00168 
00169 // End of file

© Nokia 2009

Back to top