-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEditHostDialog.cpp
94 lines (77 loc) · 2.47 KB
/
EditHostDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
////////////////////////////////////////////////////////////////////////////////
//! \file EditHostDialog.cpp
//! \brief The EditHostDialog class definition.
//! \author Chris Oldwood
#include "Common.hpp"
#include "EditHostDialog.hpp"
#include <NCL/Socket.hpp>
#include <WCL/BusyCursor.hpp>
#include <NCL/AutoWinSock.hpp>
#include <Core/Algorithm.hpp>
////////////////////////////////////////////////////////////////////////////////
//! Constructor.
EditHostDialog::EditHostDialog()
: CDialog(IDD_ADDEDIT_HOST)
{
DEFINE_CTRL_TABLE
CTRL(IDC_HOST_NAME, &m_hostnameEditor)
CTRL(IDC_MONITOR, &m_monitorSwitch)
CTRL(IDC_LOGON, &m_logonEditor)
CTRL(IDC_ENVIRONMENT, &m_environmentEditor)
CTRL(IDC_DESCRIPTION, &m_descriptionEditor)
END_CTRL_TABLE
DEFINE_CTRLMSG_TABLE
CMD_CTRLMSG(IDC_CHECK_HOST, BN_CLICKED, &EditHostDialog::onCheckHost)
END_CTRLMSG_TABLE
}
////////////////////////////////////////////////////////////////////////////////
//! Dialog initialisation handler.
void EditHostDialog::OnInitDialog()
{
m_hostnameEditor.Text(m_host.m_name);
m_monitorSwitch.Check(m_host.m_monitor);
m_logonEditor.Text(m_host.m_logon);
m_environmentEditor.Text(m_host.m_environment);
m_descriptionEditor.Text(m_host.m_description);
}
////////////////////////////////////////////////////////////////////////////////
//! OK button handler.
bool EditHostDialog::OnOk()
{
if (m_hostnameEditor.TextLength() == 0)
{
AlertMsg(TXT("Please enter the name of the host."));
m_hostnameEditor.Focus();
return false;
}
tstring hostname = m_hostnameEditor.Text();
if (Core::exists(m_hosts, hostname))
{
AlertMsg(TXT("The host '%s' is already being monitored."), hostname.c_str());
m_hostnameEditor.Focus();
return false;
}
m_host.m_name = hostname;
m_host.m_environment = m_environmentEditor.Text();
m_host.m_description = m_descriptionEditor.Text();
m_host.m_monitor = m_monitorSwitch.IsChecked();
m_host.m_logon = m_logonEditor.Text();;
return true;
}
////////////////////////////////////////////////////////////////////////////////
//! Check host button handler.
void EditHostDialog::onCheckHost()
{
if (m_hostnameEditor.TextLength() == 0)
{
AlertMsg(TXT("Please enter the name of the host first."));
return;
}
CBusyCursor busyCursor;
AutoWinSock autoWinSock;
bool resolved = CSocket::canResolveHostname(m_hostnameEditor.Text());
if (resolved)
NotifyMsg(TXT("The hostname appears to be valid."));
else
AlertMsg(TXT("The hostname does not appear to be valid."));
}