Class: UI::ServiceStatus Deprecated

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

Overview

Deprecated.

Use CWM::ServiceWidget instead.

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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ServiceStatus.

Parameters:

  • service (Yast2::Systemd::Service)

    systemd service. Usually the easiest way is just calling Yast2::Systemd::Service.find("name_of_the_service") Note that this widget will #start and #stop the service by itself but the actions referenced by the flags (reloading and enabling/disabling) are expected to be done by the caller, when the whole configuration is written.

  • reload_flag (Boolean) (defaults to: true)

    Initial value for the "reload" checkbox. Keep in mind it will always be displayed as unchecked if the service is not active, despite the real value.

  • reload_flag_label (Symbol) (defaults to: :reload)

    Type of label for the "reload" checkbox. :reload means the service will be reloaded. :restart means the service will be restarted.



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 Attribute Details

#id_prefixObject (readonly, protected)

Returns the value of attribute id_prefix.



150
151
152
# File 'library/general/src/lib/ui/service_status.rb', line 150

def id_prefix
  @id_prefix
end

Instance Method Details

#enabled_flag?Boolean

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

Returns:

  • (Boolean)


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.

Returns:

  • (Symbol)

    Label for the managed event



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
146
# File 'library/general/src/lib/ui/service_status.rb', line 128

def help
  # TRANSLATORS: do not modify %{reload_label}
  format(_(
           "<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

#label_and_action_widgetsObject (protected)



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'library/general/src/lib/ui/service_status.rb', line 189

def label_and_action_widgets
  # use active and not running. See https://bugzilla.suse.com/show_bug.cgi?id=1080738#c3
  if @service.active?
    [
      # TRANSLATORS: status of a service
      Label(_("running")),
      Label(" "),
      PushButton(Id("#{id_prefix}_stop"), _("Stop now"))
    ]
  else
    [
      # TRANSLATORS: status of a service
      Label(_("stopped")),
      Label(" "),
      PushButton(Id("#{id_prefix}_start"), _("Start now"))
    ]
  end
end

#on_boot_widgetObject (protected)

Widget to configure the status on boot



164
165
166
167
168
169
170
171
172
173
# File 'library/general/src/lib/ui/service_status.rb', line 164

def on_boot_widget
  Left(
    CheckBox(
      Id("#{id_prefix}_enabled"),
      Opt(:notify),
      _("Start During System Boot"),
      @enabled_flag
    )
  )
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.active?)
  Yast::UI.ChangeWidget(Id("#{id_prefix}_reload"), :Value, @service.active? && @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

Returns:

  • (Boolean)


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

def reload_flag?
  @reload_flag
end

#reload_widgetObject (protected)

Widget to configure reloading of the running service



176
177
178
179
180
181
182
183
184
185
186
187
# File 'library/general/src/lib/ui/service_status.rb', line 176

def reload_widget
  opts = [:notify]
  opts << :disabled unless @service.active?
  Left(
    CheckBox(
      Id("#{id_prefix}_reload"),
      Opt(*opts),
      @reload_label,
      @service.active? && @reload_flag
    )
  )
end

#status_widgetObject (protected)

Widget displaying the status and associated buttons



153
154
155
156
157
158
159
160
161
# File 'library/general/src/lib/ui/service_status.rb', line 153

def status_widget
  Left(
    HBox(
      Label(_("Current status:")),
      Label(" "),
      *label_and_action_widgets
    )
  )
end

#widgetYaST::Term

Returns:

  • (YaST::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