📄 iapconnectview.cpp
字号:
/*
* ============================================================================
* Name : CIAPConnectView from IAPConnectView.cpp
* Part of : Internet Access Points Example v2.0
* Created : 01.09.2006 by Forum Nokia
* Version : 2.0
* Copyright: Forum Nokia
* ============================================================================
*/
// INCLUDE FILES
#include <iapconnect.rsg>
#include <aknviewappui.h>
#include <avkon.hrh>
#include <AknDialog.h>
#include <eikmenup.h>
#include "IAPConnectView.h"
#include "IAPConnectContainer.h"
#include "IAPConnect.hrh"
// Uncomment to enable writing to CommDb on S60 3rd Edition, i.e. adding and
// removing IAPs (requires WriteDeviceData capability). For more information,
// please see release_notes.txt.
// #define __S60_3X_COMMDB_WRITE__
// CONSTANTS
// ================= MEMBER FUNCTIONS =======================
// Constructor
CIAPConnectView::CIAPConnectView(CIAPConnectAppUi& anAppUi) :
iAppUi(anAppUi)
{
}
// Destructor
CIAPConnectView::~CIAPConnectView()
{
if ( iContainer )
{
AppUi()->RemoveFromViewStack( *this, iContainer );
delete iContainer;
}
if (iStateText)
{
delete iStateText;
}
}
// ---------------------------------------------------------
// CIAPConnectView::ConstructL()
// Symbian two-phased constructor
// ---------------------------------------------------------
//
void CIAPConnectView::ConstructL( )
{
BaseConstructL( R_IAPCONNECT_MAIN_VIEW );
}
// ---------------------------------------------------------
// TUid CIAPConnectView::Id()
// Returns the id of the view.
// ---------------------------------------------------------
//
TUid CIAPConnectView::Id() const
{
return KViewMainId;
}
// ---------------------------------------------------------
// CIAPConnectView::HandleCommandL()
// takes care of view command handling
// ---------------------------------------------------------
//
void CIAPConnectView::HandleCommandL(TInt aCommand)
{
switch ( aCommand )
{
case EIAPConnectCmdConnect:
{
#if !defined(__SERIES60_3X__) && defined(__WINS__)
// Some 2nd Edition emulators do not handle KCommDbBearerUnknown
// correctly, in which case the emulator fails to show the
// IAP selection prompt (resulting in "General error" in
// this example). As a workaround, use KCommDbBearerPSD in the
// 2nd Ed emulator.
iAppUi.Model()->SetConnectionPreferences(KCommDbBearerPSD,
ETrue);
#else
// All devices and 3rd Edition emulator
iAppUi.Model()->SetConnectionPreferences(KCommDbBearerUnknown,
ETrue);
#endif
iAppUi.Model()->ConnectL();
iContainer->DrawNow();
break;
}
case EIAPConnectCmdConnectPSD:
{
iAppUi.Model()->SetConnectionPreferences(KCommDbBearerPSD,
EFalse);
iAppUi.Model()->ConnectL();
iContainer->DrawNow();
break;
}
case EIAPConnectCmdConnectCSD:
{
iAppUi.Model()->SetConnectionPreferences(KCommDbBearerCSD,
ETrue);
iAppUi.Model()->ConnectL();
iContainer->DrawNow();
break;
}
case EIAPConnectCmdConnectUsingAPHandler:
{
TUint32 iapId;
iAppUi.Model()->SelectAccessPointL(iapId);
if (iapId) // if iapId == 0 no access point selected
{
iAppUi.Model()->SetConnectionPreferences(KCommDbBearerUnknown,
EFalse, iapId);
iAppUi.Model()->ConnectL();
iContainer->DrawNow();
}
break;
}
case EIAPConnectCmdNewIAP:
{
// Get only IAP name from user. Other parameters are hardcoded
// and just for demonstration
if (GetIapNameL())
iAppUi.Model()->CreateNewIapL(iIapName);
break;
}
case EAknSoftkeyCancel:
{
iAppUi.Model()->Cancel();
break;
}
case EIAPConnectCmdRelease:
{
iAppUi.Model()->ReleaseL();
break;
}
case EIAPConnectCmdTerminate:
{
iAppUi.Model()->TerminateConnectionL();
break;
}
default:
{
// Exit-commands etc.
AppUi()->HandleCommandL( aCommand );
break;
}
}
}
/*
-----------------------------------------------------------------------------
void CIAPConnectView::HandleStatusPaneSizeChange()
Description: Called by framework when resource is changed.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CIAPConnectView::HandleStatusPaneSizeChange()
{
CAknView::HandleStatusPaneSizeChange(); //call to upper class
if (iContainer)
iContainer->SetRect(ClientRect());
}
// ---------------------------------------------------------
// CIAPConnectView::DoActivateL()
// ---------------------------------------------------------
//
void CIAPConnectView::DoActivateL(
const TVwsViewId& /*aPrevViewId*/,TUid /*aCustomMessageId*/,
const TDesC8& /*aCustomMessage*/)
{
CreateContainerL(); // Create the container
if (iStateText)
{
iContainer->ChangeStateL(*iStateText);
}
}
// ---------------------------------------------------------
// CIAPConnectView::DoDeactivate()
// ---------------------------------------------------------
//
void CIAPConnectView::DoDeactivate()
{
if ( iContainer )
{
AppUi()->RemoveFromViewStack( *this, iContainer );
delete iContainer;
iContainer = NULL;
}
}
// ---------------------------------------------------------
// CIAPConnectView::ChangeStateL(const TDesC& aText)
//
// Shows the application state change to the user
// ---------------------------------------------------------
//
void CIAPConnectView::ChangeStateL(const TDesC& aText)
{
// Make sure the container has been created (at application start-up,
// this ChangeStateL-method might get called before this view
// has been set active).
CreateContainerL();
if (iStateText)
{
delete iStateText;
iStateText = NULL;
}
iStateText = HBufC::NewL(aText.Length());
*iStateText = aText;
iContainer->ChangeStateL(aText);
}
// ---------------------------------------------------------
// CIAPConnectView::CreateContainerL()
//
// Creates the container for this view
// ---------------------------------------------------------
//
void CIAPConnectView::CreateContainerL()
{
// Get the client rect via CAknAppUi instead of CAknView
// (a workaround for a bug where CAknView::ClientRect() returns
// a TRect that is too small)
TRect rect = iAppUi.ClientRect();
if (!iContainer)
{
iContainer = new (ELeave) CIAPConnectContainer;
iContainer->SetMopParent(this);
iContainer->ConstructL( rect );
AppUi()->AddToStackL( *this, iContainer );
}
}
// ---------------------------------------------------------
// CIAPConnectView::DynInitMenuPaneL(TInt aResourceId,
// CEikMenuPane* aMenuPane)
//
// Called by the framework when this view's menu is shown
// ---------------------------------------------------------
//
void CIAPConnectView::DynInitMenuPaneL(TInt aResourceId,
CEikMenuPane* aMenuPane)
{
if (aResourceId == R_IAPCONNECT_MENU)
{
// In order to add and remove IAPs we need WriteDeviceData
// capability. For more information, please see release_notes.txt.
// If we do not have the capability, we hide the menu options for
// these operations.
// __S60_3X_COMMDB_WRITE__ can be found at the beginning of
// this file.
#if defined(__SERIES60_3X__) && !defined(__S60_3X_COMMDB_WRITE__)
aMenuPane->SetItemDimmed(EIAPConnectCmdNewIAP, ETrue);
aMenuPane->SetItemDimmed(EIAPConnectCmdShowRemoveIAPView,
ETrue);
#endif
if (iAppUi.Model()->GetState() == EIAPConnectStateConnected)
{
// Hide commands meant for making a connection
// (only one connection can be made at a time)
aMenuPane->SetItemDimmed(EIAPConnectCmdConnect, ETrue);
aMenuPane->SetItemDimmed(EIAPConnectCmdConnectPSD, ETrue);
aMenuPane->SetItemDimmed(EIAPConnectCmdConnectCSD, ETrue);
aMenuPane->SetItemDimmed(EIAPConnectCmdConnectUsingAPHandler,
ETrue);
// Show commands meant for releasing a connection and for
// viewing its info
aMenuPane->SetItemDimmed(EIAPConnectCmdShowConnectionInfo,
EFalse);
aMenuPane->SetItemDimmed(EIAPConnectCmdRelease, EFalse);
aMenuPane->SetItemDimmed(EIAPConnectCmdTerminate, EFalse);
}
else
{
// Show
aMenuPane->SetItemDimmed(EIAPConnectCmdConnect, EFalse);
aMenuPane->SetItemDimmed(EIAPConnectCmdConnectPSD, EFalse);
aMenuPane->SetItemDimmed(EIAPConnectCmdConnectCSD, EFalse);
aMenuPane->SetItemDimmed(EIAPConnectCmdConnectUsingAPHandler,
EFalse);
// Hide
aMenuPane->SetItemDimmed(EIAPConnectCmdShowConnectionInfo,
ETrue);
aMenuPane->SetItemDimmed(EIAPConnectCmdRelease, ETrue);
aMenuPane->SetItemDimmed(EIAPConnectCmdTerminate, ETrue);
}
}
}
// ---------------------------------------------------------
// CIAPConnectView::GetIapNameL()
//
// Querys the name of the IAP to be used when creating a new IAP
// ---------------------------------------------------------
//
TBool CIAPConnectView::GetIapNameL()
{
CAknTextQueryDialog* iapNameDialog =
CAknTextQueryDialog::NewL(iIapName, CAknQueryDialog::ENoTone);
if (!iapNameDialog->ExecuteLD(R_IAPCONNECT_IAPNAME_DIALOG))
return EFalse;
return ETrue;
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -