|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : SIPExAddrQueryDlg.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 "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 if ( iAddress.Length() > 0 ) 00081 { 00082 static_cast< CAknQueryControl* >( 00083 Control( ESIPExInviteAddressId ) )->SetTextL( iAddress ); 00084 } 00085 } 00086 00087 // ----------------------------------------------------------------------------- 00088 // CSIPExAddrQueryDlg::OkToExitL 00089 // From CEikDialog. 00090 // Validates the given address and if not correct notifies user with info 00091 // message. 00092 // ----------------------------------------------------------------------------- 00093 // 00094 TBool CSIPExAddrQueryDlg::OkToExitL( TInt aKeyCode ) 00095 { 00096 TBool isOk( ETrue ); 00097 00098 if ( aKeyCode == EAknSoftkeyOk ) 00099 { 00100 static_cast< CAknQueryControl* >( 00101 Control( ESIPExInviteAddressId ) )->GetText( iAddress ); 00102 00103 // Check the validity of the given address 00104 HBufC8* address = HBufC8::NewLC( iAddress.Length() ); 00105 TPtr8 paddress( address->Des() ); 00106 CnvUtfConverter::ConvertFromUnicodeToUtf8( paddress, iAddress ); 00107 00108 if ( !AddressValid( paddress ) ) 00109 { 00110 HBufC* txt = StringLoader::LoadLC( R_ERROR_IN_ADDRESS_TXT ); 00111 CEikonEnv::Static()->InfoMsg( txt->Des() ); 00112 CleanupStack::PopAndDestroy( txt ); 00113 isOk = EFalse; 00114 } 00115 00116 CleanupStack::PopAndDestroy( address ); 00117 } 00118 00119 return isOk; 00120 } 00121 00122 00123 // ----------------------------------------------------------------------------- 00124 // CSIPExAddrQueryDlg::HandleResourceChange 00125 // From CEikDialog. 00126 // ----------------------------------------------------------------------------- 00127 // 00128 void CSIPExAddrQueryDlg::HandleResourceChange( TInt aType ) 00129 { 00130 CAknDialog::HandleResourceChange( aType ); 00131 00132 if ( aType == KEikDynamicLayoutVariantSwitch ) 00133 { 00134 TRect mainPaneRect; 00135 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, 00136 mainPaneRect ); 00137 SetRect( mainPaneRect ); 00138 00139 DrawNow(); 00140 } 00141 } 00142 00143 // ----------------------------------------------------------------------------- 00144 // CSIPExAddrQueryDlg::AddressValid 00145 // Checks if user typed address is valid sip address. 00146 // ----------------------------------------------------------------------------- 00147 // 00148 TBool CSIPExAddrQueryDlg::AddressValid( const TDesC8& aSipAddr ) 00149 { 00150 _LIT8( KTypeSIP, "sip" ); 00151 00152 TUriParser8 parser; 00153 User::LeaveIfError( parser.Parse( aSipAddr ) ); 00154 CUri8* uri8 = CUri8::NewLC( parser ); 00155 00156 TBool valid( ETrue ); 00157 00158 if ( uri8->Uri().Extract( EUriScheme ).CompareF( KTypeSIP() ) != KErrNone ) 00159 { 00160 valid = EFalse; 00161 } 00162 if ( uri8->Uri().Extract( EUriUserinfo ) == KNullDesC8 ) 00163 { 00164 valid = EFalse; 00165 } 00166 if ( uri8->Uri().Extract( EUriHost ) == KNullDesC8 ) 00167 { 00168 valid = EFalse; 00169 } 00170 CleanupStack::PopAndDestroy( uri8 ); 00171 00172 return valid; 00173 } 00174 00175 // End of file
|
© Nokia 2006 |