📄 infoapp.cpp
字号:
hr = pDetailsScreen->CreateDialogScreen();
if (FAILED(hr))
{
goto exit;
}
hr = PhInfoGlobalData_t::pPhInfoApp->AddToScreenSequence (
InfoApp_t::IdGalContactDetailsDialog,
pDetailsScreen->GetDialog()
);
exit:
if (FAILED(hr) && pDetailsScreen)
{
delete pDetailsScreen;
}
return hr;
}
/*------------------------------------------------------------------------------
InfoApp_t::AddToScreenSequence
Append a new screen to the sequence.
------------------------------------------------------------------------------*/
HRESULT
InfoApp_t::AddToScreenSequence (
ScreenId Id,
HWND NewWindow
)
{
if (!NewWindow || Id < IdDefault || Id >= IdLast)
{
ASSERT(0);
return E_INVALIDARG;
}
//
// Update the ScreenSequence and TopWindow with newly created screen information.
//
ScreenInformation screenInfo = {NewWindow, Id};
if(!m_ScreenSequence.push_front(screenInfo))
{
return E_OUTOFMEMORY;
}
//foreground our main window...
return SetForegroundWindow(NewWindow) ? S_OK : S_FALSE;
}
/*---------------------------------------------------------------------------------
InfoApp_t::CreatePhoneInformationMenuScreen
This is a helper function to create PhMenuScreens needed for Phone Information.
---------------------------------------------------------------------------------*/
HWND
InfoApp_t::CreatePhoneInformationMenuScreen (
InfoApp_t::ScreenId Id
)
{
PHMS_ITEM* pMenuItems;
UINT ScreenIdentifier;
int MenuItemsCount;
int TitleId;
switch (Id)
{
case InfoApp_t::IdDefault:
pMenuItems = const_cast<PHMS_ITEM*>(MainMenuItems);
TitleId = IDS_TITLE_DIRECTORY;
MenuItemsCount = _countof (MainMenuItems);
ScreenIdentifier = PHINFO_DEFAULT_SCREEN_ID;
break;
case InfoApp_t::IdCallLogMenu:
pMenuItems = const_cast<PHMS_ITEM*>(CallLogMenuItems);
TitleId = IDS_TITLE_CALLLOGS;
MenuItemsCount = _countof (CallLogMenuItems);
ScreenIdentifier = PHINFO_CALL_LOG_MENU_SCREEN_ID;
break;
case InfoApp_t::IdContactMenu:
pMenuItems = const_cast<PHMS_ITEM*>(ContactsMenuItems);
TitleId = IDS_TITLE_DIRECTORY;
MenuItemsCount = _countof (ContactsMenuItems);
ScreenIdentifier = PHINFO_CONTACT_MENU_SCREEN_ID;
break;
default:
ASSERT (FALSE);
return NULL;
}
PH_MENU_SCREEN_PARAMETERS MenuParameters = {0};
MenuParameters.Instance = GlobalData_t::s_ModuleInstance;
MenuParameters.Flags = VDF_TYPE_MODELESS;
MenuParameters.NotificationMsg = WM_MENU_DONE;
MenuParameters.Owner = m_HiddenWindow;
MenuParameters.StructSize = sizeof(PH_MENU_SCREEN_PARAMETERS);
MenuParameters.ItemCount = MenuItemsCount;
MenuParameters.pMenuScreenItems = pMenuItems;
MenuParameters.Id = ScreenIdentifier;
MenuParameters.pTitle = CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, TitleId);
if (!PHMenuScreen(&MenuParameters))
{
ASSERT(FALSE);
return NULL;
}
return MenuParameters.result.Dialog;
}
/*---------------------------------------------------------------------------------
InfoApp_t::GetCallerInfoDB
Initialize access to caller info DB.
---------------------------------------------------------------------------------*/
HRESULT
InfoApp_t::GetCallerInfoDB(
IVoIPCallerInfoDB** ppDB
)
{
if (! ppDB)
{
ASSERT(FALSE);
return E_POINTER;
}
*ppDB = NULL;
HRESULT hr = S_OK;
if (! m_cpCallerInfoDB)
{
hr = PHInitCallerInfoDB(&m_cpCallerInfoDB);
}
if (FAILED(hr))
{
COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Failed to initiate Caller info DB. hr = 0x%x", hr));
return hr;
}
*ppDB = m_cpCallerInfoDB;
(*ppDB)->AddRef();
return S_OK;
}
/*---------------------------------------------------------------------------------
InfoApp_t::GetCallLogDB
Initialize access to call log DB.
---------------------------------------------------------------------------------*/
HRESULT
InfoApp_t::GetCallLogDB(
IVoIPCallLogDB** ppDB
)
{
if (! ppDB)
{
ASSERT(FALSE);
return E_POINTER;
}
*ppDB = NULL;
HRESULT hr = S_OK;
if (! m_cpCallLogDB)
{
hr = PHInitCallLogDB(&m_cpCallLogDB);
}
if (FAILED(hr))
{
COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Failed to initiate Call log DB. hr = 0x%x", hr));
return hr;
}
*ppDB = m_cpCallLogDB;
(*ppDB)->AddRef();
return S_OK;
}
/*---------------------------------------------------------------------------------
InfoApp_t::GetExchangeClient
Initialize access to exchange client.
---------------------------------------------------------------------------------*/
HRESULT
InfoApp_t::GetExchangeClient(
IExchangeClient** ppExchangeClient
)
{
if (! ppExchangeClient)
{
ASSERT(FALSE);
return E_POINTER;
}
//clear the OUT pointer
*ppExchangeClient = NULL;
HRESULT hr = S_OK;
WCHAR ServerName[MAX_PATH] = L"";
//if we already have our exchange client, no need to re-initialize it
if (m_cpExchangeClient != NULL)
{
goto exit;
}
hr = m_cpExchangeClient.CoCreateInstance(
CLSID_ExchangeClient
);
if (FAILED(hr))
{
COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"CoCreateInstance failed for exchange client. hr = 0x%x", hr));
return hr;
}
//set the HTTP proxy (if needed)
hr = SetHttpProxy();
if (FAILED(hr))
{
COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Failed to set Http proxy server. hr = 0x%x", hr));
}
hr = m_cpExchangeClient->Initialize(
static_cast<IExchangeClientRequestCallback*>(this)
);
if (FAILED(hr))
{
COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Failed to initialize exchange client. hr = 0x%x", hr));
m_cpExchangeClient = NULL;
return hr;
}
hr = SetExchangeServer();
if (FAILED(hr))
{
COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Failed to set exchange server. hr = 0x%x", hr));
}
exit:
*ppExchangeClient = m_cpExchangeClient;
(*ppExchangeClient)->AddRef();
return S_OK;
}
/*---------------------------------------------------------------------------------
InfoApp_t::GetOutlookApp
Initialize access to Outlook app (POOM).
---------------------------------------------------------------------------------*/
HRESULT InfoApp_t::GetOutlookApp(
IPOutlookApp** ppOutlookApp
)
{
if (m_cpOutlookApp)
{
goto exit;
}
//co create the object...
HRESULT hr = m_cpOutlookApp.CoCreateInstance(
CLSID_Application
);
if (FAILED(hr))
{
COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"CoCreateInstance failed for outlook app. hr = 0x%x", hr));
return hr;
}
hr = m_cpOutlookApp->Logon(NULL);
if (FAILED(hr))
{
COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Logon failed for outlook app. hr = 0x%x", hr));
m_cpOutlookApp = NULL;
return hr;
}
exit:
*ppOutlookApp = m_cpOutlookApp;
(*ppOutlookApp)->AddRef();
return S_OK;
}
/*------------------------------------------------------------------------------
InfoApp_t::OnAuthRequestComplete
Handle the completion of a user authentication request (PIN dialog)
Parameters:
UserAuthenticated: TRUE- the user is authenticated, FALSE they are not
------------------------------------------------------------------------------*/
HRESULT
InfoApp_t::OnAuthRequestComplete(
AuthenticationResult_e Result
)
{
if (! m_WaitingForAuth)
{
//no longer waiting for auth...
return S_FALSE;
}
CComPtr<IUnknown> cpNewSpeedDialRecord;
ScreenId id = m_PendingAuthScreenId;
cpNewSpeedDialRecord = m_cpPendingAuthSpeedDialRecord;
//Reset our wait variables
m_WaitingForAuth = false;
m_PendingAuthScreenId = IdDefault;
m_cpPendingAuthSpeedDialRecord = NULL;
if (Result != AuthSucceeded)
{
//User failed authentication challenge -
//do not let them access the app
GoBackToPreviousScreen();
return S_OK;
}
if (id == IdSpeedDialEdit)
{
return CreateSpeedDialEditScreen(
cpNewSpeedDialRecord
);
}
//
// User is authenticated, navigate as they previously requested
//
return CreateNewScreen(id);
}
/*------------------------------------------------------------------------------
InfoApp_t::OnRequestProgress
This callback function handles the exchange client
posting progress about a request - notify the top level window
------------------------------------------------------------------------------*/
HRESULT InfoApp_t::OnRequestProgress (
IExchangeClientRequest* piRequest,
ExchangeClientRequestStatus status
)
{
if(m_ScreenSequence.empty())
{
return S_FALSE;
}
HWND TopWindow = m_ScreenSequence.front().WindowHandle;
if (! IsWindow(TopWindow))
{
return S_FALSE;
}
SendMessage (
TopWindow,
WM_EXCHANGE_QUERY_COMPLETED,
(WPARAM)status,
(LPARAM)piRequest
);
return S_OK;
}
HRESULT InfoApp_t::OnShutdown()
{
//if we don't have an exchange client pointer then we are not
//shutting down - we are simply re-initializing the exchange client
if (m_cpExchangeClient)
{
m_cpExchangeClient = NULL;
Exit();
}
return S_OK;
}
HRESULT InfoApp_t::ListenForSettingsChanges()
{
ASSERT(
m_HiddenWindow &&
m_NotifyHandle == NULL
);
return RegistryNotifyWindow(
SN_VOIP_UPDATEDEXCHANGESETTINGS_ROOT,
SN_VOIP_UPDATEDEXCHANGESETTINGS_PATH,
SN_VOIP_UPDATEDEXCHANGESETTINGS_VALUE,
m_HiddenWindow,
WM_INFOAPP_SETTINGSCHANGE,
100,
NULL,
&m_NotifyHandle
);
}
HRESULT InfoApp_t::OnSettingsChange(
DWORD ChangedSettings
)
{
//
// Check if one of the settings PhInfo app is interested in has changed.
//
if ((ChangedSettings & VOIP_ALL_EXCHANGE_SETTINGS) == 0)
{
return S_FALSE;
}
//
// Update the proxy.
//
HRESULT hr;
if (ChangedSettings & EXCHANGE_PROXY)
{
hr = SetHttpProxy();
if (FAILED(hr))
{
COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Failed to set Http proxy. hr = 0x%x", hr));
ASSERT(FALSE);
}
}
//
// If Exchange client is initialized, update the server name.
//
if (ChangedSettings & EXCHANGE_SERVER)
{
hr = SetExchangeServer();
if (FAILED(hr))
{
COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Failed to set exchange server. hr = 0x%x", hr));
ASSERT(FALSE);
}
}
//
// Send a message to the PhInfo top window to refresh.
//
SendMessage (
m_ScreenSequence.front().WindowHandle,
WM_SCREEN_REFRESH,
0,
0
);
return S_OK;
}
/*---------------------------------------------------------------------------------
InfoApp_t::SetExchangeServer
Read exchange server name from the registry and associate it with exchange client
---------------------------------------------------------------------------------*/
HRESULT
InfoApp_t::SetExchangeServer()
{
if (m_cpExchangeClient == NULL)
{
return S_FALSE;
}
HRESULT hr = S_FALSE;
WCHAR ServerName[MAX_PATH] = L"";
hr = RegistryGetString (
SN_VOIP_EXCHANGESERVER_ROOT,
SN_VOIP_EXCHANGESERVER_PATH,
SN_VOIP_EXCHANGESERVER_VALUE,
ServerName,
_countof(ServerName)
);
if (SUCCEEDED(hr) && ServerName[0])
{
hr = m_cpExchangeClient->SetServer(ServerName);
if (FAILED(hr))
{
COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Failed to set exchange server. hr = 0x%x", hr));
ASSERT(FALSE);
}
}
return hr;
}
/*---------------------------------------------------------------------------------
InfoApp_t::SetHttpProxy
Read Http proxy from the registry.
---------------------------------------------------------------------------------*/
HRESULT
InfoApp_t::SetHttpProxy()
{
WCHAR HttpProxy[MAX_PATH] = L"";
CHAR szProxy[MAX_PATH] = "";
//read the proxy that was just set
HRESULT hr = RegistryGetString (
SN_VOIP_EXCHANGEPROXY_ROOT,
SN_VOIP_EXCHANGEPROXY_PATH,
SN_VOIP_EXCHANGEPROXY_VALUE,
HttpProxy,
_countof(HttpProxy)
);
if (FAILED(hr))
{
COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Failed to read Http proxy from registry. hr = 0x%x", hr));
return hr;
}
if (HttpProxy[0] == 0)
{
COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Http Proxy is not set."));
return E_FAIL;
}
WideCharToMultiByte(
CP_ACP,
0,
HttpProxy,
-1,
szProxy,
_countof(szProxy),
NULL,
NULL
);
INTERNET_PROXY_INFO info = {0};
// if the szProxy is empty string, disable the proxy
// by passing the INTERNET_OPEN_TYPE_DIRECT flag
info.dwAccessType = szProxy[0] ? INTERNET_OPEN_TYPE_PROXY : INTERNET_OPEN_TYPE_DIRECT;
info.lpszProxy = (LPTSTR)szProxy;
hr = Delay_UrlMkSetSessionOption(
INTERNET_OPTION_PROXY,
(void*)&info,
sizeof(INTERNET_PROXY_INFO),
0
);
ASSERT(SUCCEEDED(hr));
BOOL fRefresh = TRUE;
Delay_UrlMkSetSessionOption(
INTERNET_OPTION_REFRESH,
(void*)&fRefresh,
sizeof(BOOL),
0
);
Delay_InternetSetOption(
NULL,
INTERNET_OPTION_SETTINGS_CHANGED,
NULL,
0
);
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -