chxavnetconnectui.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:8k
源码类别:
Symbian
开发平台:
Visual C++
- /************************************************************************
- * chxavnetconnectui.cpp
- * ----------------------
- *
- * Synopsis:
- * Access point selection and connect note UI logic implementation.
- *
- *
- * Target:
- * Symbian OS
- *
- *
- * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
- *
- ************************************************************************/
- #include "hxcom.h"
- #include "ihxpckts.h" //IHXValues
- #include "hxprefs.h" //IHXPreferences
- #include "hxsym_debug.h"
- #include "hxsym_leaveutil.h"
- #include "hxdebug_hxapi.h"
- #include "hxapihelp_player.h"
- #include "hxapihelp.h"
- #include "chxavmessagedialog.h"
- #include "chxavcleanstring.h"
- #include "chxavcleanupstack.h"
- #include "comptr.h"
- #include "comptr_traits.h"
- #include "chxavaccesspointdb.h"
- #include "chxavutil.h"
- #include "chxavmisc.h"
- #include "chxavconfignames.h"
- #include "chxavnetconnectui.h"
- namespace
- {
- inline
- bool SupportsInternetAccessL(CHXAvAccessPointDB* pDb,TUint32 ulAccessPointId)
- {
- TUint32 wapId = pDb->GetWapIdFromAPIdL(ulAccessPointId);
- return pDb->SupportsInternetAccessL(wapId);
- }
- UINT32 GetActiveID(IHXAccessPointManager* pManager)
- {
- HX_ASSERT(pManager);
- comptr<IHXValues> info;
- UINT32 id = 0;
- if (HXR_OK == pManager->GetActiveAccessPointInfo(info.AsRef()))
- {
- info->GetPropertyULONG32("ID", id);
- }
- return id;
- }
- }
- /*
- * CHXAvNetConnectUI
- * ------------------
- * Ctor
- *
- */
- CHXAvNetConnectUI::CHXAvNetConnectUI()
- : m_bDoingSelect(false)
- {
- }
- void CHXAvNetConnectUI::ConstructL(IUnknown* pUnk,
- const CHXAvCommand& cmdCancelConnect)
- {
- m_prefs.From(pUnk);
- m_factory.From(pUnk);
- #if defined(SYMBAINPLAYER_INCLUDE_CONNECT_NOTE_UI)
- m_spConnectNote = new (ELeave) CHXAvWaitNote();
- m_spConnectNote->SetTextL(CHXAvCleanString(R_AVP_ST_CONNECTING)());
- m_spConnectNote->SetCancelCommandL(cmdCancelConnect);
- #endif
- }
- void CHXAvNetConnectUI::ShowConnectNote()
- {
- #if defined(SYMBAINPLAYER_INCLUDE_CONNECT_NOTE_UI)
- if(!m_bDoingSelect && !m_spConnectNote->IsShowing())
- {
- TRAPD(err, m_spConnectNote->StartL(true /*delay*/));
- }
- #endif
- }
- void CHXAvNetConnectUI::HideConnectNote()
- {
- #if defined(SYMBAINPLAYER_INCLUDE_CONNECT_NOTE_UI)
- TRAPD(err, m_spConnectNote->EndL());
- #endif
- }
- /*
- * ~CHXAvNetConnectUI
- * -------------------
- *
- */
- CHXAvNetConnectUI::~CHXAvNetConnectUI()
- {
- }
- HX_RESULT
- CHXAvNetConnectUI::DoSelectAccessPointL(IHXAccessPointManager* pManager,
- IHXAccessPointSelectorResponse* pResponse)
- {
- DPRINTF(SYMP_INFO, ("CHXAvNetConnectUI::SelectAccessPoint()n"));
- HX_RESULT res = HXR_FAIL;
- m_bDoingSelect = true;
- if(pResponse)
- {
- // Get the default configured internet access point from prefs
- CHXAvAccessPointDB* pDb = new (ELeave) CHXAvAccessPointDB;
- AUTO_PUSH_POP_DEL(pDb);
- pDb->ConstructL();
- TUint32 defaultAccessPointId = GetAndValidateDefaultAccessPointL(pDb);
- if (defaultAccessPointId == 0)
- {
- // Alert and prompt user to select a default access point
- defaultAccessPointId = PromptForDefaultAccessPointL(pDb);
- }
- TUint32 preferredAccessPointId = defaultAccessPointId;
- // Find out if there is an active (connected) access point
- TUint32 activeAccessPointId = GetActiveID(pManager);
- if (0 != activeAccessPointId)
- {
- // An access point is active (connected)
- if(SupportsInternetAccessL(pDb, activeAccessPointId) &&
- defaultAccessPointId != activeAccessPointId &&
- defaultAccessPointId != 0)
- {
- // Connected access point is different from our default,
- // but we can still use it. Since we can use the active access
- // point (it suports internet access), give user an option to
- // disconnect (or not) from the active one
- if (!PromptForDisconnectL(pDb, activeAccessPointId))
- {
- // User opts to use active AP even though it is not the
- // configured default
- preferredAccessPointId = activeAccessPointId;
- // XXXLCM should we prompt to save this
- // (or automatically do so) if no default is configured?
- }
- }
- }
- if(preferredAccessPointId)
- {
- // Sanity check
- HX_ASSERT(pDb->IsValidL(preferredAccessPointId));
- HX_ASSERT(SupportsInternetAccessL(pDb, preferredAccessPointId));
- comptr<IHXValues> apInfo;
- if ((HXR_OK == m_factory->CreateInstance(CLSID_IHXValues,apInfo.AsPtrPtr())) &&
- (HXR_OK == apInfo->SetPropertyULONG32("ID", preferredAccessPointId)))
- {
- pResponse->SelectAccessPointDone(HXR_OK, apInfo);
- res = HXR_OK;
- }
- }
- else
- {
- CHXAvMessageDialog::DoAlertInfoL(CHXAvCleanString(R_AVP_UNABLE_TO_PROCEED_NO_ACCESS_POINT)(), true);
- }
- }
- m_bDoingSelect = false;
- if(SUCCEEDED(res))
- {
- // ensure connect note is showing
- ShowConnectNote();
- }
- return res;
- }
- TUint32 CHXAvNetConnectUI::GetAndValidateDefaultAccessPointL(CHXAvAccessPointDB* pDb)
- {
- TUint32 defaultAccessPointId = GetAccessPointFromPrefsL(pDb);
- if(defaultAccessPointId)
- {
- // Check validitiy of configured access point.
- // This is a rare but possible case.
- if(pDb->IsValidL(defaultAccessPointId))
- {
- TUint32 wapId = pDb->GetWapIdFromAPIdL(defaultAccessPointId);
- if(!pDb->SupportsInternetAccessL(wapId))
- {
- // We can't use this because it doesn't support IP connections
- defaultAccessPointId = 0;
- }
- }
- else
- {
- // Not in database
- defaultAccessPointId = 0;
- }
- }
- return defaultAccessPointId;
- }
- TUint32 CHXAvNetConnectUI::PromptForDefaultAccessPointL(CHXAvAccessPointDB* pDb)
- {
- TUint32 ret = 0;
- #if defined(SYMBAINPLAYER_INCLUDE_CONNECT_NOTE_UI)
- // hide connect note if it is showing
- m_spConnectNote->EndL();
- #endif
- CHXAvMessageDialog::DoAlertInfoL(CHXAvCleanString(R_AVP_CONFIGURE_ACCESS_POINT)(), true);
- TInt wapId = CHXAvMisc::RunAccessPointSettingPageL(0/*default*/);
- if( wapId != 0 )
- {
- HX_ASSERT(pDb->SupportsInternetAccessL(wapId));
- // User selected something. Translate wap ap id to internet ap id and save to prefs
- ret = pDb->GetAPIdFromWapIdL(wapId);
- prefs::Write(m_factory, m_prefs, CHXAV_AccessPoint, ret);
- }
- return ret;
- }
- bool CHXAvNetConnectUI::PromptForDisconnectL(CHXAvAccessPointDB* pDb,
- TUint32 activeAccessPointId)
- {
- #if defined(SYMBAINPLAYER_INCLUDE_CONNECT_NOTE_UI)
- // hide connect note if it is showing
- m_spConnectNote->EndL();
- #endif
- // Connected access point is different from our default, but we
- // can still use it.Since we can use the active access point
- // (it suports internet access), give user an option to disconnect
- // (or not) from the active one
- HBufC* pName = pDb->AllocAccessPointNameL(activeAccessPointId);
- AUTO_PUSH_POP_DEL(pName);
- CHXAvCleanString disconnectString(R_CONF_DISCONNECT_ACCESS_POINT, *pName);
- return CHXAvMessageDialog::DoQueryL(disconnectString());
- }
- /*
- * GetAccessPointFromPrefs
- * -----------------------
- * Return the stored value for the default accesspoint. First try the integer value.
- * If that fails, get the string value. If the string value is not there either,
- * return 0.
- *
- */
- TUint32
- CHXAvNetConnectUI::GetAccessPointFromPrefsL(CHXAvAccessPointDB* pDb)
- {
- TUint32 accessPoint = 0;
- accessPoint = prefs::GetUINT32(m_prefs, CHXAV_AccessPoint, 0);
- if (accessPoint == 0)
- {
- CHXString accessPointStr = prefs::GetString(m_prefs, CHXAV_AccessPointStr, "");
- if (!accessPointStr.IsEmpty())
- {
- accessPoint = pDb->GetIapIDFromNameL(accessPointStr);
- }
- }
- return accessPoint;
- }
- void
- CHXAvNetConnectUI::OnNetConnect()
- {
- #if defined(SYMBAINPLAYER_INCLUDE_CONNECT_NOTE_UI)
- #error add code here
- #endif
- //XXXLCM should check m_spPlayer->HasPresStarted()
- ShowConnectNote();
- }
- void
- CHXAvNetConnectUI::OnStop()
- {
- HideConnectNote();
- }
- void
- CHXAvNetConnectUI::OnBeginBuffering(bool /*bIsBegin*/)
- {
- // in case this is first resume after connect
- HideConnectNote();
- }
- void
- CHXAvNetConnectUI::OnError(HX_RESULT code)
- {
- // in case error comes while connecting
- HideConnectNote();
- }