Class: Yast2::ServiceWidget

Inherits:
Object
  • Object
show all
Extended by:
Yast::I18n
Includes:
Yast::I18n, Yast::Logger, Yast::UIShortcuts
Defined in:
library/systemd/src/lib/yast2/service_widget.rb

Overview

TODO:

Allow to specify the widget ID. Currently, it uses always the same, so you can not use more than one instance of this class at the same time.

Class that represents widget that allows configuration of services. It uses to hold configuration SystemService or CompoundService. It can work with both and for usage it really depends if it should configure single or multiple services

Examples:

usage of widget with workflow with read + propose + show_dialog + write

class Workflow
  def initialize
    @service = Yast2::SystemService.find("my_service")
  end

  def propose
    # The default service widget action can be proposed by the current
    # service action
    @service.restart
    @service.start_mode = :on_demand
  end

  def show_dialog
    service_widget = ServiceWidget.new(@service)
    # Or can be set by the service_widget
    service_widget.default_action = :reload if service.running?

    content = VBox(
      ...,
      service_widget.content
    )
    loop do
      input = UI.UserInput
      service_widget.handle_input(input)
      ...
    end
    service_widget.store
  end

  def write
    @service.save
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service) ⇒ ServiceWidget

creates new widget instance for given service

Parameters:



81
82
83
84
85
86
87
# File 'library/systemd/src/lib/yast2/service_widget.rb', line 81

def initialize(service)
  textdomain "base"
  @service = service
  # When the service is active, by default, propose to reload or restart
  # it after writting the configuration (bsc#1158946)
  init_default_action
end

Instance Attribute Details

#current_actionSymbol (readonly)

It stores the selected service action

Returns:

  • (Symbol)

    service action (:nothing for no action)

See Also:



77
78
79
# File 'library/systemd/src/lib/yast2/service_widget.rb', line 77

def current_action
  @current_action
end

Instance Method Details

#contentYast::Term

gets widget term

Returns:

  • (Yast::Term)


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'library/systemd/src/lib/yast2/service_widget.rb', line 101

def content
  Frame(
    _("Service Configuration"),
    VBox(
      Left(
        HBox(
          Label(_("Current status:")),
          HSpacing(1),
          Label(Id(:service_widget_status), Opt(:hstretch), status)
        )
      ),
      Left(action_widget),
      Left(autostart_widget)
    )
  )
end

#default_action=(value) ⇒ Object

Set the given action as the current action selected by the widget, when no action is given it will not touch the service unless modified in the selection list

Parameters:

  • value (Symbol, nil)

    uses :nothing in case of no action given

See Also:



95
96
97
# File 'library/systemd/src/lib/yast2/service_widget.rb', line 95

def default_action=(value)
  @current_action = value || :nothing
end

#handle_input(event_id) ⇒ nil

handles event to dynamically react on user configuration. For events that does not happen inside widget it is ignored.

Parameters:

  • event_id (Object)

    id of UI element that cause event

Returns:

  • (nil)

    it returns nil as it should allow to continue dialog loop



134
135
136
137
138
# File 'library/systemd/src/lib/yast2/service_widget.rb', line 134

def handle_input(event_id)
  log.info "handle event #{event_id}"

  nil
end

#helpString

Returns the service widget help text

Returns:

  • (String)


153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'library/systemd/src/lib/yast2/service_widget.rb', line 153

def help
  # TRANSLATORS: helptext for the service current status, the header
  helptext = _("<h2>Service configuration</h2>")
  # TRANSLATORS: helptext for the service current status
  helptext += _(
    "<h3>Current status</h3>" \
    "Displays the current status of the service."
  )

  # TRANSLATORS: helptext for the "After writting configuration" service widget option
  helptext += _(
    "<h3>After writing configuration</h3>" \
    "Allow to change the service status immediately after accepting the changes. Available
    options depend on the current state. The <b>Keep current state</b> special action leaves the
    service state untouched."
  )

  # TRANSLATORS: helptext for the "After reboot" service widget option
  helptext + _(
    "<h3>After reboot</h3>" \
    "Let choose if service should be started automatically on boot. Some services could be
    configured <b>on demand</b>, which means that the associated socket will be running and
    start the service if needed."
  )
end

#refreshnil

Updates the widget with current values of service

Useful to update the information after certain actions like "Apply changes"

Returns:

  • (nil)


123
124
125
126
127
128
# File 'library/systemd/src/lib/yast2/service_widget.rb', line 123

def refresh
  Yast::UI.ChangeWidget(Id(:service_widget_status), :Value, status)
  Yast::UI.ChangeWidget(Id(:service_widget_action), :Items, action_items)
  Yast::UI.ChangeWidget(Id(:service_widget_autostart), :Items, autostart_items)
  nil
end

#storeObject

Note:

it requires content of dialog to query, so cannot be called after DialogClose or if

Stores current configuration. Should be called always before dialog close, even when going back so configuration is persistent when going again forward. another dialog is displayed instead of the one with #content



144
145
146
147
148
# File 'library/systemd/src/lib/yast2/service_widget.rb', line 144

def store
  service.reset # so we start from scratch
  store_action
  store_autostart
end