Class: UI::ServiceStatus

Inherits:
Object
  • Object
show all
Includes:
Yast::I18n, Yast::Logger, Yast::UIShortcuts
Defined in:
library/general/src/lib/ui/service_status.rb

Overview

Widgets for managing the status of services (both currently and on system boot) and the behavior associated to those widgets

As long as #handle_input is invoked in the event loop, the widget will handle interactive starting and stopping of the service on user demand.

It also provides checkboxes (reload_flag and enabled_flag) for the user to specify whether the service must be reloaded/restarted after configuration changes and whether it must be enabled at boot time.

Instance Method Summary collapse

Constructor Details

#initialize(service, reload_flag: true, reload_flag_label: :reload) ⇒ ServiceStatus



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'library/general/src/lib/ui/service_status.rb', line 51

def initialize(service, reload_flag: true, reload_flag_label: :reload)
  @service = service
  @reload_flag = reload_flag

  @enabled_flag = @service.enabled?
  @id_prefix = "_srv_status_#{@service.name}"
  textdomain "base"
  @reload_label = if reload_flag_label == :restart
    _("Restart After Saving Settings")
  else
    _("Reload After Saving Settings")
  end
end

Instance Method Details

#enabled_flag?Boolean

Checks if the user requested the service to be enabled on boot



116
117
118
# File 'library/general/src/lib/ui/service_status.rb', line 116

def enabled_flag?
  @enabled_flag
end

#handle_input(input) ⇒ Symbol

Handles the input triggered by the widgets, this method must be called in the event loop of the dialog using the component.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'library/general/src/lib/ui/service_status.rb', line 82

def handle_input(input)
  case input
  when "#{id_prefix}_stop"
    @service.stop
    refresh
    :stop
  when "#{id_prefix}_start"
    @service.start
    refresh
    :start
  when "#{id_prefix}_reload"
    @reload_flag = Yast::UI.QueryWidget(Id(input), :Value)
    :reload_flag
  when "#{id_prefix}_enabled"
    @enabled_flag = Yast::UI.QueryWidget(Id(input), :Value)
    :enabled_flag
  else
    log.info "Input not handled by ServiceStatus: #{input}"
    :ignored
  end
end

#helpObject

Content for the help



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'library/general/src/lib/ui/service_status.rb', line 128

def help
  _(
    "<p><b><big>Current status</big></b><br>\n"\
    "Displays the current status of the service. The status will remain "\
    "the same after saving the settings, independently of the value of "\
    "'start service during boot'.</p>\n"\
    "<p><b><big>%{reload_label}</big></b><br>\n"\
    "Only applicable if the service is currently running. "\
    "Ensures the running service reloads the new configuration after "\
    "saving it (either finishing the dialog or pressing the apply "\
    "button).</p>\n"\
    "<p><b><big>Start During System Boot</big></b><br>\n"\
    "Check this field to enable the service at system boot. "\
    "Un-check it to disable the service. "\
    "This does not affect the current status of the service in the already "\
    "running system.</p>\n"
  ) % { reload_label: @reload_label }
end

#refreshObject

Updates the widget to reflect the current status of the service and the settings



106
107
108
109
110
111
# File 'library/general/src/lib/ui/service_status.rb', line 106

def refresh
  Yast::UI.ChangeWidget(Id("#{id_prefix}_reload"), :Enabled, @service.running?)
  Yast::UI.ChangeWidget(Id("#{id_prefix}_reload"), :Value, @service.running? && @reload_flag)
  Yast::UI.ChangeWidget(Id("#{id_prefix}_enabled"), :Value, @enabled_flag)
  Yast::UI.ReplaceWidget(Id("#{id_prefix}_status"), status_widget)
end

#reload_flag?Boolean

Checks if the user requested the service to be reloaded when saving



123
124
125
# File 'library/general/src/lib/ui/service_status.rb', line 123

def reload_flag?
  @reload_flag
end

#widgetYaST::Term



66
67
68
69
70
71
72
73
74
75
76
# File 'library/general/src/lib/ui/service_status.rb', line 66

def widget
  Frame(
    _("Service Status"),
    VBox(
      ReplacePoint(Id("#{id_prefix}_status"), status_widget),
      reload_widget,
      VSpacing(),
      on_boot_widget
    )
  )
end