S60 3rd Edition SDK for Symbian OS
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-2006 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 : iAddress( aAddress ), iMsg( aMsg )
00061     {
00062     }
00063 
00064 // -----------------------------------------------------------------------------
00065 // CSIPExIMDialog::~CSIPExIMDialog
00066 // Destructor
00067 // -----------------------------------------------------------------------------
00068 //
00069 CSIPExIMDialog::~CSIPExIMDialog()
00070     {
00071     }
00072 
00073 // -----------------------------------------------------------------------------
00074 // CSIPExIMDialog::ConstructL
00075 // Symbian 2nd phase constructor that might leave.
00076 // -----------------------------------------------------------------------------
00077 //
00078 void CSIPExIMDialog::ConstructL()
00079     {
00080     }
00081 
00082 // -----------------------------------------------------------------------------
00083 // CSIPExIMDialog::PreLayoutDynInitL
00084 // From CEikDialog. Called before drawing the dialog.
00085 // If address variable has used earlier use that value as default.
00086 // -----------------------------------------------------------------------------
00087 //
00088 void CSIPExIMDialog::PreLayoutDynInitL()
00089     {
00090     if( iAddress.Length() > 0 )
00091         {
00092         static_cast< CAknQueryControl* >( 
00093                 Control( ESIPExIMAddressLineId ) )->SetTextL( iAddress );
00094         }
00095     }
00096 
00097 // -----------------------------------------------------------------------------
00098 // CSIPExIMDialog::OkToExitL
00099 // From CEikDialog. Called when user presses dialog's button.
00100 // Validates the given address and if not correct notifies user with info
00101 // message. The length of the message is limited in resource file to 256.
00102 // The limitation is not in SIP implementation.
00103 // -----------------------------------------------------------------------------
00104 //
00105 TBool CSIPExIMDialog::OkToExitL(TInt aKeyCode)
00106     {   
00107     TBool isOk( ETrue );
00108     
00109     if( aKeyCode == EAknSoftkeyOk )
00110         {
00111         static_cast< CAknQueryControl* >( 
00112                 Control( ESIPExIMMessageLineId ) )->GetText( iMsg );
00113         static_cast< CAknQueryControl* >( 
00114                 Control( ESIPExIMAddressLineId ) )->GetText( iAddress );
00115 
00116         // Check the validity of the given address
00117         HBufC8* address = HBufC8::NewLC( iAddress.Length() );
00118         TPtr8 paddress( address->Des() );
00119         CnvUtfConverter::ConvertFromUnicodeToUtf8( paddress, iAddress );
00120         
00121         if ( !AddressValid( paddress ) )
00122             {
00123             HBufC* txt = StringLoader::LoadLC( R_ERROR_IN_ADDRESS_TXT );
00124             CEikonEnv::Static()->InfoMsg( txt->Des() );
00125             CleanupStack::PopAndDestroy( txt );
00126             isOk = EFalse;
00127             }
00128                
00129         CleanupStack::PopAndDestroy( address );
00130         }
00131 
00132     return isOk;
00133     }
00134  
00135  // -----------------------------------------------------------------------------
00136 // CSIPExIMDialog::HandleResourceChange
00137 // From CEikDialog
00138 // -----------------------------------------------------------------------------
00139 //    
00140 void CSIPExIMDialog::HandleResourceChange( TInt aType )
00141     {
00142     CAknDialog::HandleResourceChange( aType );
00143         
00144     if ( aType == KEikDynamicLayoutVariantSwitch )
00145         {
00146         TRect mainPaneRect;
00147         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, 
00148                                            mainPaneRect );
00149         SetRect( mainPaneRect );
00150         
00151         DrawNow();
00152         }
00153     }
00154     
00155 // -----------------------------------------------------------------------------
00156 // CSIPExIMDialog::AddressValid
00157 // Checks if user typed address is valid sip address.
00158 // -----------------------------------------------------------------------------
00159 //    
00160 TBool CSIPExIMDialog::AddressValid( const TDesC8& aSipAddr )
00161     {
00162     _LIT8( KTypeSIP, "sip" );
00163     
00164     TUriParser8 parser;
00165     User::LeaveIfError( parser.Parse( aSipAddr ) ); 
00166     CUri8* uri8 = CUri8::NewLC( parser );
00167     
00168     TBool valid( ETrue );
00169     
00170     if ( uri8->Uri().Extract( EUriScheme ).CompareF( KTypeSIP() ) != KErrNone )
00171         {
00172         valid = EFalse;
00173         }
00174     if ( uri8->Uri().Extract( EUriUserinfo ) == KNullDesC8 )
00175         {
00176         valid = EFalse;
00177         }
00178     if ( uri8->Uri().Extract( EUriHost ) == KNullDesC8 )
00179         {
00180         valid = EFalse;
00181         }
00182     CleanupStack::PopAndDestroy( uri8 );
00183         
00184     return valid;           
00185     }
00186 
00187 // End of file

© Nokia 2006

Back to top