📄 editserversettings.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
#include <winuserm.h>
#include "EditServerSettings.hpp"
#include "SettingsApp.hpp"
#include "resource.h"
#include "ControlDefinitions.h"
#include "Controls.hpp"
#include "VoIPNotify.hpp"
#include "PhoneAPI.hpp"
#include "regext.h"
#include "Layout.hpp"
const WCHAR EditServerSettingsDialog_t::sc_SIPSettingsTemplate[] = \
L"<set name=\"SIPSettings\" value=\" "
L"<provision key='%1' name='SIPSettings'>" //provision key
L"<user "
L"account='%2' " //account name
L"password='%3' " //password
L"uri='%4' " //uri
L"allowedauth='digest'/>"
L"<sipsrv "
L"addr='%5' " //sip proxy
L"protocol='%6' " //protocol
L"role='proxy' "
L"> "
L"<session party='First' type='pc2pc' /> <session party='First' type='pc2ph' />"
L"</sipsrv> "
L"<sipsrv "
L"addr='%7' " //sip registrar
L"protocol='%6' " //protocol
L"role='registrar' /"
L"> "
L"</provision> "
L"\"/>";
const WCHAR EditServerSettingsDialog_t::sc_BackupSIPSettingsTemplate[] = \
L"<set name=\"BackupSIPSettings\" value=\" "
L"<provision key='%1' name='BackupSIPSettings'>" //provision key
L"<user "
L"account='%2' " //account name
L"password='%3' " //password
L"uri='%4' " //uri
L"allowedauth='digest'/>"
L"<sipsrv "
L"addr='%5' " //backup proxy
L"protocol='%6' " //protocol
L"role='proxy' "
L"> "
L"<session party='First' type='pc2pc' /> <session party='First' type='pc2ph' />"
L"</sipsrv> "
L"<sipsrv "
L"addr='%7' " //backup registrar
L"protocol='%6' " //protocol
L"role='registrar' /"
L"> "
L"</provision> "
L"\"/>";
const WCHAR EditServerSettingsDialog_t::sc_VoicemailSettingsTemplate[] = \
L"<set name=\"VoicemailSettings\" value=\" "
L"<provision key='%1' name='VoicemailSettings'> " //provision key
L"<user "
L"account='%2' " //account name
L"password='%3' " //password
L"uri='%4' " //uri
L"allowedauth='digest'/> "
L"<sipsrv "
L"addr='%5' " //voicemail proxy
L"protocol='%6' " //protocol
L"role='proxy' "
L"> "
L"<session party='First' type='pc2pc' /> "
L"</sipsrv> "
L"</provision> "
L"\"/>";
const WCHAR EditServerSettingsDialog_t::sc_VoicemailNumberTemplate[] = L"<set name=\"VoicemailNumber\" value=\"%1\" />";
const WCHAR EditServerSettingsDialog_t::sc_ProvisionTemplate[] = \
L"<voip-provision>"
L"%1 \n" // SIPSettings
L"%2 \n" // VoicemailSettings
L"%3 \n" // VoicemailNumber
L"%4 \n" // Backup Settings
L"</voip-provision>";
const WCHAR EditServerSettingsDialog_t::sc_EmptyString[] = L"";
const WCHAR EditServerSettingsDialog_t::sc_DeleteSIPSettings[] = L"<delete name=\"SIPSettings\" />";
const WCHAR EditServerSettingsDialog_t::sc_DeleteBackupSIPSettings[] = L"<delete name=\"BackupSIPSettings\" />";
const WCHAR EditServerSettingsDialog_t::sc_DeleteVoicemailSettings[] = L"<delete name=\"VoicemailSettings\" />";
const WCHAR EditServerSettingsDialog_t::sc_DeleteVoicemailNumber[] = L"<delete name=\"VoicemailNumber\" />";
EditServerSettingsDialog_t::EditServerSettingsDialog_t(
bool NeedProvisionData
)
{
m_UpdatedCategoryFlag = 0;
//set those pointers to empty string to simplify the 'replacement' logic
m_pSIPSettings = (WCHAR*)sc_EmptyString;
m_pBackupSIPSettings = (WCHAR*)sc_EmptyString;
m_pVoicemailNumber = (WCHAR*)sc_EmptyString;
m_pVoicemailSettings = (WCHAR*)sc_EmptyString;
m_pProvisionDocument = (WCHAR*)sc_EmptyString;
m_CurrentMenuId = 0;
m_NeedProvisionData = NeedProvisionData;
}
EditServerSettingsDialog_t::~EditServerSettingsDialog_t()
{
CleanupAllPointers();
}
HRESULT
EditServerSettingsDialog_t::CreateDialogScreen(
)
{
return SettingsDialog_t::CreateDialogScreen(
IDS_EMPTY,
IDS_SERVERSETTINGSEDIT_TITLE,
IDMB_EDITSERVERSETTINGS_EMPTY_BUTTONS,
PHSETTINGS_EDITSERVERSETTINGS_SCREEN_ID
);
}
HRESULT
EditServerSettingsDialog_t::Initialize()
{
HRESULT hr = S_OK;
ListBox_t ListBox;
ListBox = GetDlgItem (m_DialogScreen, IDC_LISTBOX);
IVoIPDisplayItem* pLabeledItem;
WCHAR wszStore[MAX_PATH] = L"";
CleanupAllPointers();
hr = OnResetContent();
if (FAILED(hr))
{
return hr;
}
if (m_NeedProvisionData)
{
ServerSettings_t ServerSettings;
hr = ServerSettings.RetrieveSettingsFromProvision();
if (FAILED(hr))
{
return hr;
}
}
for (unsigned Index = 0; Index < ServerSettings_t::LastSetting; Index++)
{
hr = PHCreateLabeledEditDisplayItem(
CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, ServerSettings_t::sc_ServerSettings[Index].LabelId),
WS_BORDER | ServerSettings_t::sc_ServerSettings[Index].EsExtra,
MAX_PATH - 1,
&pLabeledItem,
Layout_t::SettingsLabelWidth(),
ServerSettings_t::sc_ServerSettings[Index].ImeType
);
if (FAILED(hr))
{
return hr;
}
hr = pLabeledItem->SetText(ServerSettings_t::s_ServerSettings[Index].get_buffer());
if (FAILED(hr))
{
delete pLabeledItem;
return hr;
}
hr = ListBox.AddItem(-1, pLabeledItem);
if (FAILED(hr))
{
delete pLabeledItem;
return hr;
}
}
UpdateMenuBar();
UpdateStatusHeader();
return hr;
}
HRESULT
EditServerSettingsDialog_t::OnCommand(
WPARAM wParam
)
{
HRESULT hr = S_OK;
if (HIWORD(wParam) == LBN_SELCHANGE && LOWORD(wParam) == IDC_LISTBOX)
{
UpdateMenuBar();
UpdateStatusHeader();
return S_OK;
}
switch (wParam)
{
case IDC_INPUT:
//todo
break;
case IDC_BACKSPACE:
return SendMessage(
GetFocus(),
WM_CHAR,
L'\b',
0
);
case IDC_SAVE:
return OnSave();
case IDCANCEL:
return GetSettingsApp()->GoBackToPreviousScreen();
case IDC_TRANSPORT_UDP:
return UpdateTransportMode(L"UDP");
case IDC_TRANSPORT_TCP:
return UpdateTransportMode(L"TCP");
case IDC_TRANSPORT_TCS:
return UpdateTransportMode(L"TCS");
default:
return UpdateMenuBar();
}
return S_OK;
}
HRESULT
EditServerSettingsDialog_t::UpdateStatusHeader(
void
)
{
const IVoIPDisplayItem* pSelectedDisplayItem = NULL;
ListBox_t ListBox;
ListBox = GetDlgItem (m_DialogScreen, IDC_LISTBOX);
int SelectedIndex = ListBox.GetCurSel();
if (SelectedIndex < 0 || SelectedIndex >= ServerSettings_t::LastSetting)
{
return S_FALSE;
}
UINT statusHeader = ServerSettings_t::sc_ServerSettings[SelectedIndex].NotificationId;
STATUS_HEADER_PARAMETERS Parameters = {
GlobalData_t::s_ModuleInstance,
statusHeader,
shpDefault,
0,
INFINITE
};
return (HRESULT)SendMessage(
GetDlgItem(m_DialogScreen, IDC_STATUSREGION),
WM_STATUSHEADER_ADDSTATUSNOTIFICATION,
(WPARAM)sizeof(STATUS_HEADER_PARAMETERS),
(LPARAM)&Parameters
);
}
HRESULT
EditServerSettingsDialog_t::UpdateMenuBar(
void
)
{
HRESULT hr = S_OK;
IVoIPDisplayItem* pSelectedItem = NULL;
int SelectedIndex = 0;
BOOL HasText = FALSE;
MenuBar_t MenuBar;
//Figure out which item is selected...
GetSelectedDisplayItem(
&pSelectedItem,
&SelectedIndex
);
if (pSelectedItem == NULL)
{
return E_UNEXPECTED;
}
MenuBar = GetDlgItem(m_DialogScreen, IDC_MENUBAR);
if (SelectedIndex == ServerSettings_t::SIPTransport)
{
//is the menu bar correct?
if (m_CurrentMenuId == IDMB_EDITSERVERSETTINGS_TRANSPORT_BUTTONS)
{
return S_OK;
}
//nope, update the menu bar
m_CurrentMenuId = IDMB_EDITSERVERSETTINGS_TRANSPORT_BUTTONS;
return MenuBar.SetMenu(
GlobalData_t::s_ModuleInstance,
m_CurrentMenuId
);
}
//otherwise this is an editable item
WCHAR Buf[3] = L"";
pSelectedItem->GetText(Buf, _countof(Buf));
//does the item have text?
HasText = (Buf[0] != 0);
//do we need to update the menu
if (m_CurrentMenuId != IDMB_EDITSERVERSETTINGS_BACKSPACE_BUTTONS)
{
m_CurrentMenuId = IDMB_EDITSERVERSETTINGS_BACKSPACE_BUTTONS;
MenuBar.SetMenu(
GlobalData_t::s_ModuleInstance,
m_CurrentMenuId
);
}
//show or hide the backspace button
return MenuBar.ShowMenuButton(
IDC_BACKSPACE,
HasText
);
}
void
EditServerSettingsDialog_t::GetSelectedDisplayItem(
IVoIPDisplayItem** ppSelectedDisplayItem,
int* pItemIndex
)
{
if (ppSelectedDisplayItem == NULL)
{
return;
}
ListBox_t ListBox;
ListBox = GetDlgItem (m_DialogScreen, IDC_LISTBOX);
*ppSelectedDisplayItem = NULL;
int SelectedIndex = SendMessage(
ListBox,
LB_GETCURSEL,
0, 0
);
if (SelectedIndex == -1)
{
return;
}
if (pItemIndex != NULL)
{
*pItemIndex = SelectedIndex;
}
*ppSelectedDisplayItem = static_cast<IVoIPDisplayItem*>(ListBox.GetItem(SelectedIndex));
return;
}
HRESULT
EditServerSettingsDialog_t::UpdateTransportMode(
const WCHAR* c_wszTransportMode
)
{
IVoIPDisplayItem* pSelectedItem = NULL;
int IdxSelected;
GetSelectedDisplayItem(
&pSelectedItem,
&IdxSelected
);
if (pSelectedItem == NULL)
{
return E_UNEXPECTED;
}
return pSelectedItem->SetText(c_wszTransportMode);
}
HRESULT
EditServerSettingsDialog_t::OnSave(
void
)
{
HRESULT hr = S_OK;
IVoIPDisplayItem* pSelectedItem = NULL;
WCHAR Text[MAX_PATH] = L"";
ListBox_t ListBox;
ListBox = GetDlgItem (m_DialogScreen, IDC_LISTBOX);
// Provisioning format string
for (unsigned int Index = 0; Index < ServerSettings_t::LastSetting; Index ++)
{
pSelectedItem = static_cast<IVoIPDisplayItem*>(ListBox.GetItem(Index));
if (pSelectedItem == NULL)
{
return E_UNEXPECTED;
}
hr = pSelectedItem->GetText(Text, _countof(Text));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -