⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sipeximdialog.cpp

📁 an example for sip for symbian
💻 CPP
字号:
/*
* ==============================================================================
*  Name        : CSIPExIMDialog.cpp
*  Part of     : SIPEx
*  Interface   : 
*  Description : 
*  Version     : 
*
*  Copyright (c) 2004-2006 Nokia Corporation.
*  This material, including documentation and any related 
*  computer programs, is protected by copyright controlled by 
*  Nokia Corporation.
* ==============================================================================
*/

// INCLUDES
#include "SIPExIMDialog.h"
#include "SIPEx.hrh"
#include <SIPEx.rsg>
#include <eikenv.h>
#include <avkon.hrh>
#include <stringloader.h>
#include <aknquerycontrol.h>
#include <akndef.h>
#include <Uri8.h>
#include <utf.h> 

// -----------------------------------------------------------------------------
// CSIPExIMDialog::NewL
// Static constructor
// -----------------------------------------------------------------------------
//
CSIPExIMDialog* CSIPExIMDialog::NewL( TDes& aAddress, TDes& aMsg )
    {
    CSIPExIMDialog* self = NewLC( aAddress, aMsg );
    CleanupStack::Pop(self);
    return self;
    }

// -----------------------------------------------------------------------------
// CSIPExIMDialog::NewLC
// Static constructor. On return the instance is left to the CleanupStack.
// -----------------------------------------------------------------------------
//
CSIPExIMDialog* CSIPExIMDialog::NewLC( TDes& aAddress, TDes& aMsg )
    {
    CSIPExIMDialog* self = new (ELeave) CSIPExIMDialog( aAddress, aMsg );
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
    }

// -----------------------------------------------------------------------------
// CSIPExIMDialog::CSIPExIMDialog
// C++ default constructor. Initializes the member variables with default values
// from client.
// -----------------------------------------------------------------------------
//
CSIPExIMDialog::CSIPExIMDialog( TDes& aAddress, TDes& aMsg )
: iAddress( aAddress ), iMsg( aMsg )
    {
    }

// -----------------------------------------------------------------------------
// CSIPExIMDialog::~CSIPExIMDialog
// Destructor
// -----------------------------------------------------------------------------
//
CSIPExIMDialog::~CSIPExIMDialog()
    {
    }

// -----------------------------------------------------------------------------
// CSIPExIMDialog::ConstructL
// Symbian 2nd phase constructor that might leave.
// -----------------------------------------------------------------------------
//
void CSIPExIMDialog::ConstructL()
    {
    }

// -----------------------------------------------------------------------------
// CSIPExIMDialog::PreLayoutDynInitL
// From CEikDialog. Called before drawing the dialog.
// If address variable has used earlier use that value as default.
// -----------------------------------------------------------------------------
//
void CSIPExIMDialog::PreLayoutDynInitL()
    {
    if( iAddress.Length() > 0 )
        {
        static_cast< CAknQueryControl* >( 
                Control( ESIPExIMAddressLineId ) )->SetTextL( iAddress );
        }
    }

// -----------------------------------------------------------------------------
// CSIPExIMDialog::OkToExitL
// From CEikDialog. Called when user presses dialog's button.
// Validates the given address and if not correct notifies user with info
// message. The length of the message is limited in resource file to 256.
// The limitation is not in SIP implementation.
// -----------------------------------------------------------------------------
//
TBool CSIPExIMDialog::OkToExitL(TInt aKeyCode)
    {   
    TBool isOk( ETrue );
    
    if( aKeyCode == EAknSoftkeyOk )
        {
        static_cast< CAknQueryControl* >( 
                Control( ESIPExIMMessageLineId ) )->GetText( iMsg );
        static_cast< CAknQueryControl* >( 
                Control( ESIPExIMAddressLineId ) )->GetText( iAddress );

        // Check the validity of the given address
        HBufC8* address = HBufC8::NewLC( iAddress.Length() );
        TPtr8 paddress( address->Des() );
        CnvUtfConverter::ConvertFromUnicodeToUtf8( paddress, iAddress );
        
        if ( !AddressValid( paddress ) )
            {
            HBufC* txt = StringLoader::LoadLC( R_ERROR_IN_ADDRESS_TXT );
            CEikonEnv::Static()->InfoMsg( txt->Des() );
            CleanupStack::PopAndDestroy( txt );
            isOk = EFalse;
            }
               
        CleanupStack::PopAndDestroy( address );
        }

    return isOk;
    }
 
 // -----------------------------------------------------------------------------
// CSIPExIMDialog::HandleResourceChange
// From CEikDialog
// -----------------------------------------------------------------------------
//    
void CSIPExIMDialog::HandleResourceChange( TInt aType )
    {
    CAknDialog::HandleResourceChange( aType );
	
    if ( aType == KEikDynamicLayoutVariantSwitch )
        {
        TRect mainPaneRect;
        AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, 
                                           mainPaneRect );
        SetRect( mainPaneRect );
        
        DrawNow();
        }
    }
    
// -----------------------------------------------------------------------------
// CSIPExIMDialog::AddressValid
// Checks if user typed address is valid sip address.
// -----------------------------------------------------------------------------
//    
TBool CSIPExIMDialog::AddressValid( const TDesC8& aSipAddr )
    {
    _LIT8( KTypeSIP, "sip" );
    
    TUriParser8 parser;
    User::LeaveIfError( parser.Parse( aSipAddr ) ); 
    CUri8* uri8 = CUri8::NewLC( parser );
    
    TBool valid( ETrue );
    
    if ( uri8->Uri().Extract( EUriScheme ).CompareF( KTypeSIP() ) != KErrNone )
        {
        valid = EFalse;
        }
    if ( uri8->Uri().Extract( EUriUserinfo ) == KNullDesC8 )
        {
        valid = EFalse;
        }
    if ( uri8->Uri().Extract( EUriHost ) == KNullDesC8 )
        {
        valid = EFalse;
        }
    CleanupStack::PopAndDestroy( uri8 );
        
    return valid;           
    }

// End of file

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -