Skip to content

Commit

Permalink
Fixes according review
Browse files Browse the repository at this point in the history
  • Loading branch information
mchf committed Nov 23, 2016
1 parent 1d0400d commit d6022e4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
19 changes: 11 additions & 8 deletions src/include/network/routines.rb
Expand Up @@ -996,15 +996,18 @@ def confirmed_detection(hwtype)
# @param [Array<String>] list of incorrectly configured devices
# @return [String] a message stating that incorrect DHCLIENT_SET_HOSTNAME setup was detected
def fix_dhclient_msg(devs)
_(
format(
"DHCLIENT_SET_HOSTNAME option is set for more than one interface,\n" \
"or global default is set incorrectly.\n" \
"This causes indeterministic behavior.\n\n" \
format(
_(
"Setting hostname over DHCP is set incorrectly.\n\n" \
"Either it is set for multiple interfaces or\n" \
"global default is set incorrectly.\n" \
"Select just one device and / or do not set global\n" \
"value. You can pick up proper configuration in\n" \
"\"Set Hostname via DHCP\" widget.\n\n" \
"Affected devices:\n" \
"%s\n",
devs.join(" ")
)
"%s\n"
),
devs.join(" ")
)
end

Expand Down
46 changes: 23 additions & 23 deletions src/include/network/services/dns.rb
Expand Up @@ -112,20 +112,20 @@ def initialize_network_services_dns(include_target)
Hostname.ValidDomain
)
},
"DHCP_IFACES" => {
"DHCP_HOSTNAME" => {
"widget" => :custom,
"custom_widget" => HBox(
Label(_("Set Hostname via DHCP")),
HSpacing(2),
ComboBox(
Id("DHCP_IFACES"),
Id("DHCP_HOSTNAME"),
"",
[]
),
ReplacePoint(Id("dh_host_text"), Empty())
),
"init" => fun_ref(method(:InitDhcpIfaces), "void (string)"),
"store" => fun_ref(method(:StoreDhcpIfaces), "voide (string, map)")
"init" => fun_ref(method(:InitDhcpHostname), "void (string)"),
"store" => fun_ref(method(:StoreDhcpHostname), "void (string, map)")
},
"WRITE_HOSTNAME" => {
"widget" => :checkbox,
Expand Down Expand Up @@ -223,7 +223,7 @@ def initialize_network_services_dns(include_target)
),
VBox(
Left("WRITE_HOSTNAME"),
Left("DHCP_IFACES")
Left("DHCP_HOSTNAME")
)
)
),
Expand Down Expand Up @@ -253,7 +253,7 @@ def initialize_network_services_dns(include_target)
"HOSTNAME",
"HOSTNAME_GLOBAL",
"DOMAIN",
"DHCP_IFACES",
"DHCP_HOSTNAME",
"WRITE_HOSTNAME",
"MODIFY_RESOLV",
"PLAIN_POLICY",
Expand Down Expand Up @@ -409,18 +409,18 @@ def StoreHnWidget(key, _event)
nil
end

# Checks whether setting hostname via DHCP is allowed
def use_dhcp_hostname?
UI.QueryWidget(Id("DHCP_IFACES"), :Value) != "none"
end

NONE_LABEL = "no".freeze
ANY_LABEL = "any".freeze
NO_CHANGE_LABEL = "no_change".freeze

# Init handler for DHCP_IFACES
def InitDhcpIfaces(_key)
UI.ChangeWidget(Id("DHCP_IFACES"), :Enabled, has_dhcp?)
# Checks whether setting hostname via DHCP is allowed
def use_dhcp_hostname?
UI.QueryWidget(Id("DHCP_HOSTNAME"), :Value) != NONE_LABEL
end

# Init handler for DHCP_HOSTNAME
def InitDhcpHostname(_key)
UI.ChangeWidget(Id("DHCP_HOSTNAME"), :Enabled, has_dhcp?)

hostname_ifaces = LanItems.find_set_hostname_ifaces
selected = DNS.dhcp_hostname ? ANY_LABEL : NONE_LABEL
Expand All @@ -435,27 +435,27 @@ def InitDhcpIfaces(_key)
selected = hostname_ifaces.first
end
# translators: no device selected placeholder
items << Item(Id(NONE_LABEL), _(NONE_LABEL), selected == NONE_LABEL)
items << Item(Id(NONE_LABEL), _("no"), selected == NONE_LABEL)
# translators: placeholder for "set hostname via any DHCP aware device"
items << Item(Id(ANY_LABEL), _("yes: " + ANY_LABEL), selected == ANY_LABEL)
items << Item(Id(ANY_LABEL), _("yes: any"), selected == ANY_LABEL)

items += LanItems.find_dhcp_ifaces.sort.map do |iface|
# translators: label is in form yes: <device name>
Item(Id(iface), _(format("yes: %s", iface)), iface == selected)
Item(Id(iface), format(_("yes: %s"), iface), iface == selected)
end

UI.ChangeWidget(Id("DHCP_IFACES"), :Items, items)
UI.ChangeWidget(Id("DHCP_HOSTNAME"), :Items, items)

log.info("InitDhcpIfaces: preselected item = #{selected}")
log.info("InitDhcpHostname: preselected item = #{selected}")

nil
end

# Store handler for DHCP_IFACES
def StoreDhcpIfaces(_key, _event)
return if !UI.QueryWidget(Id("DHCP_IFACES"), :Enabled)
# Store handler for DHCP_HOSTNAME
def StoreDhcpHostname(_key, _event)
return if !UI.QueryWidget(Id("DHCP_HOSTNAME"), :Enabled)

device = UI.QueryWidget(Id("DHCP_IFACES"), :Value)
device = UI.QueryWidget(Id("DHCP_HOSTNAME"), :Value)

case device
when NONE_LABEL
Expand Down

0 comments on commit d6022e4

Please sign in to comment.