Skip to content

Commit

Permalink
WIP: some cleanup in SrvStatusComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
ancorgs committed May 12, 2015
1 parent 5c76667 commit 6784672
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 52 deletions.
56 changes: 17 additions & 39 deletions src/include/dns-server/dialog-main.rb
Expand Up @@ -44,10 +44,7 @@ def initialize_dns_server_dialog_main(include_target)

# Do not let DnsServer manage the service status, let the user decide
DnsServer.SetWriteOnly(true)
@status_component = ::UI::SrvStatusComponent.new(
"named",
save_button_callback: method(:SaveAndRestart)
)
@status_component = ::UI::SrvStatusComponent.new("named")

@global_options_add_items = Builtins.sort(
[
Expand Down Expand Up @@ -266,42 +263,15 @@ def initialize_dns_server_dialog_main(include_target)
@dns_server_label = _("DNS Server")

@new_widgets = {
"auto_start_up" => CWMServiceStart.CreateAutoStartWidget(
{
"get_service_auto_start" => fun_ref(
DnsServer.method(:GetStartService),
"boolean ()"
),
"set_service_auto_start" => fun_ref(
DnsServer.method(:SetStartService),
"void (boolean)"
),
# radio button (starting DNS service - option 1)
"start_auto_button" => _(
"When &Booting"
),
# radio button (starting DNS service - option 2)
"start_manual_button" => _(
"&Manually"
),
"help" => Builtins.sformat(
CWMServiceStart.AutoStartHelpTemplate,
# part of help text, used to describe radiobuttons (matching starting DNS service but without "&")
_("When Booting"),
# part of help text, used to describe radiobuttons (matching starting DNS service but without "&")
_("Manually")
)
}
),
"status" => {
"start_up" => {
"widget" => :custom,
"custom_widget" => VBox(),
"init" => fun_ref(
method(:InitStatus),
method(:InitStartUp),
"void (string)"
),
"handle" => fun_ref(
method(:HandleStatus),
method(:HandleStartUp),
"symbol (string, map)"
),
"help" => "TODO"
Expand Down Expand Up @@ -446,6 +416,10 @@ def initialize_dns_server_dialog_main(include_target)
@status_component.widget,
VSpacing(),
"firewall",
VStretch(),
Right(
PushButton(Id("apply"), _("Save settings now without closing"))
)
),
# Dialog Label - DNS - expert settings
"caption" => Ops.add(
Expand All @@ -459,9 +433,9 @@ def initialize_dns_server_dialog_main(include_target)
# FIXME: new startup
"widget_names" => DnsServer.ExpertUI ?
# expert mode
["status", "firewall"] :
["start_up", "firewall"] :
# simple mode
["status", "firewall", "set_icon"]
["start_up", "firewall", "set_icon"]
},
"use_ldap" => {
"contents" => VBox("use_ldap"),
Expand Down Expand Up @@ -557,14 +531,18 @@ def initialize_dns_server_dialog_main(include_target)
@functions = { :abort => fun_ref(method(:confirmAbort), "boolean ()") }
end

def InitStatus(_key)
def InitStartUp(_key)
@status_component.refresh_widget
nil
end

def HandleStatus(_key, event)
def HandleStartUp(_key, event)
event_id = event["ID"]
@status_component.handle_input(event_id)
if event_id == "apply"
SaveAndRestart()
else
@status_component.handle_input(event_id)
end
nil
end

Expand Down
14 changes: 3 additions & 11 deletions src/lib/ui/srv_status_component.rb
Expand Up @@ -8,10 +8,9 @@ class SrvStatusComponent
include Yast::I18n
include Yast::Logger

def initialize(service_name, save_button_callback: nil, default_reload: true)
def initialize(service_name, reload: true)
@service_name = service_name
@save_button_callback = save_button_callback
@reload = default_reload
@reload = reload

@enabled = service_enabled?
@id_prefix = "_srv_status_#{@service_name}"
Expand All @@ -23,11 +22,7 @@ def widget
VSpacing(),
on_boot_widget,
VSpacing(),
reload_widget,
VSpacing(),
Right(
PushButton(Id("#{id_prefix}_apply"), _("Save settings now without closing"))
)
reload_widget
)
end

Expand All @@ -39,9 +34,6 @@ def handle_input(input)
when "#{id_prefix}_start"
start_service
refresh_widget
when "#{id_prefix}_apply"
@save_button_callback.call if @save_button_callback
refresh_widget
when "#{id_prefix}_reload"
@reload = Yast::UI.QueryWidget(Id(input), :Value)
when "#{id_prefix}_enabled"
Expand Down
10 changes: 8 additions & 2 deletions src/modules/DnsServer.pm
Expand Up @@ -1530,8 +1530,11 @@ sub Write {
y2milestone("Restarting service 'named'");
$success = Service->Restart("named")
}

# FIXME: TODO check if it's safe to move enabling/disabling to the
# !$write_only part
Service->Enable ("named");
}
Service->Enable ("named");
if (! $success)
{
# Cannot start service 'named', because of error that follows Error:. Do not translate named.
Expand All @@ -1552,8 +1555,11 @@ sub Write {
# There's no 'named' running. Reset dns forwarder again
$self->SetLocalForwarder("resolver") if GetLocalForwarder() eq "bind";
y2warning("Local forwarder set to: ".GetLocalForwarder());

# FIXME: TODO check if it's safe to move enabling/disabling to the
# !$write_only part
Service->Disable ("named");
}
Service->Disable ("named");
}

# First run finished
Expand Down

0 comments on commit 6784672

Please sign in to comment.