Class: Yast::CWMServiceStartClass

Inherits:
Module
  • Object
show all
Defined in:
library/cwm/src/modules/CWMServiceStart.rb

Instance Method Summary collapse

Instance Method Details

#AutoStartHelpString

Get the help text to the auto start widget

Returns:



251
252
253
254
255
256
257
258
259
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 251

def AutoStartHelp
  Builtins.sformat(
    AutoStartHelpTemplate(),
    # part of help text - radio button label, NO SHORTCUT!!!
    _("During Boot"),
    # part of help text - radio button label, NO SHORTCUT!!!
    _("Manually")
  )
end

#AutoStartHelpSocketTemplateString

Get the template for the help text to the auto start widget

Returns:

  • (String)

    help text template with %1 and %2 placeholders



234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 234

def AutoStartHelpSocketTemplate
  # help text for service auto start widget
  # %1, %2 and %3 are button labels
  # %1 is eg. "On -- Start Service when Booting"
  # %2 is eg. "Off -- Start Service Manually"
  # %3 is eg. "Start Service via socket"
  # (both without quotes)
  _(
    "<p><b><big>Service Start</big></b><br>\n" \
      "To start the service every time your computer is booted, set\n" \
      "<b>%1</b>. To start the service via systemd socket activation, " \
      "set <b>%3</b>.\nOtherwise set <b>%2</b>.</p>"
  )
end

#AutoStartHelpTemplateString

Get the template for the help text to the auto start widget

Returns:

  • (String)

    help text template with %1 and %2 placeholders



219
220
221
222
223
224
225
226
227
228
229
230
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 219

def AutoStartHelpTemplate
  # help text for service auto start widget
  # %1 and %2 are button labels
  # %1 is eg. "On -- Start Service when Booting"
  # %2 is eg. "Off -- Start Service Manually"
  # (both without quotes)
  _(
    "<p><b><big>Service Start</big></b><br>\n" \
      "To start the service every time your computer is booted, set\n" \
      "<b>%1</b>. Otherwise set <b>%2</b>.</p>"
  )
end

#AutoStartInit(widget, _key) ⇒ Object

Init function of the widget

Parameters:

  • widget (Hash{String => Object})

    a widget description map

  • key (String)

    strnig the widget key



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 129

def AutoStartInit(widget, _key)
  widget = deep_copy(widget)
  if !UI.WidgetExists(Id("_cwm_service_startup"))
    Builtins.y2error("Widget _cwm_service_startup does not exist")
    return
  end
  get_auto_start = Convert.convert(
    Ops.get(widget, "get_service_auto_start"),
    from: "any",
    to:   "boolean ()"
  )
  auto_start = get_auto_start.call
  UI.ChangeWidget(
    Id("_cwm_service_startup"),
    :CurrentButton,
    auto_start ? "_cwm_startup_auto" : "_cwm_startup_manual"
  )
  if Builtins.haskey(widget, "get_service_start_via_socket")
    start_via_socket = Convert.convert(
      Ops.get(widget, "get_service_start_via_socket"),
      from: "any",
      to:   "boolean ()"
    )
    if start_via_socket.call
      UI.ChangeWidget(
        Id("_cwm_service_startup"),
        :CurrentButton,
        "_cwm_startup_socket"
      )
    end
  end

  nil
end

#AutoStartInitWrapper(key) ⇒ Object

Init function of the widget

Parameters:

  • key (String)

    strnig the widget key



201
202
203
204
205
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 201

def AutoStartInitWrapper(key)
  AutoStartInit(CWM.GetProcessedWidget, key)

  nil
end

#AutoStartSocketHelpString

Get the help text to the auto start widget

Returns:



263
264
265
266
267
268
269
270
271
272
273
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 263

def AutoStartSocketHelp
  Builtins.sformat(
    AutoStartHelpSocketTemplate(),
    # part of help text - radio button label, NO SHORTCUT!!!
    _("During Boot"),
    # part of help text - radio button label, NO SHORTCUT!!!
    _("Manually"),
    # part of help text - radio button label, NO SHORTCUT!!!
    _("Via socket")
  )
end

#AutoStartStore(widget, _key, _event) ⇒ Object

Store function of the widget

Parameters:

  • widget (Hash{String => Object})

    a widget description map

  • key (String)

    strnig the widget key

  • event (Hash)

    map that caused widget data storing



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 168

def AutoStartStore(widget, _key, _event)
  widget = deep_copy(widget)
  if !UI.WidgetExists(Id("_cwm_service_startup"))
    Builtins.y2error("Widget _cwm_service_startup does not exist")
    return
  end

  auto_start = UI.QueryWidget(Id("_cwm_service_startup"), :CurrentButton) ==
    "_cwm_startup_auto"

  set_auto_start = Convert.convert(
    Ops.get(widget, "set_service_auto_start"),
    from: "any",
    to:   "void (boolean)"
  )
  set_auto_start.call(auto_start)
  if !auto_start && Builtins.haskey(widget, "set_service_start_via_socket")
    start_via_socket = Convert.convert(
      Ops.get(widget, "set_service_start_via_socket"),
      from: "any",
      to:   "void (boolean)"
    )
    start_via_socket.call(
      UI.QueryWidget(Id("_cwm_service_startup"), :CurrentButton) ==
        "_cwm_startup_socket"
    )
  end

  nil
end

#AutoStartStoreWrapper(key, event) ⇒ Object

Store function of the widget

Parameters:

  • key (String)

    strnig the widget key

  • event (Hash)

    map that caused widget data storing



210
211
212
213
214
215
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 210

def AutoStartStoreWrapper(key, event)
  event = deep_copy(event)
  AutoStartStore(CWM.GetProcessedWidget, key, event)

  nil
end

#CreateAutoStartWidget(settings) ⇒ Hash

Get the widget description map of the widget for service auto starting settings <pre>

  • “get_service_auto_start” : boolean () – function that returns if the

    service is set for automatical start-up
    
  • “set_service_auto_start” : void (boolean) – function that takes as

    an argument boolean value saying if the service is started
    automatically during booting
    
  • “get_service_start_via_socket” : boolean () – function that returns if

    the service is to be started via socket. At most one of this
    function and "get_service_auto_start" returns true (if started
    via socket, not starting automatically
    
  • “set_service_start_via_socket” : void (boolean) - function that takes

    as an argument boolean value saying if the service is started
    via socket
    
  • “start_auto_button” : string – label of the radio button to start

    the service automatically when booting
    
  • “start_socket_button” : string – label of the radio button to start

    the service via socket
    
  • “start_manual_button” : string – label of the radio button to start

    the service only manually
    
  • “help” : string – custom help for the widget. If not specified, generic

    help is used
    

</pre> Additional settings:

  • “help” : string – help to the whole widget. If not specified, generic help

    is used (button labels are patched correctly)
    

</pre>

Parameters:

  • settings (Hash{String => Object})

    a map of all parameters needed to create the widget properly

Returns:

  • (Hash)

    the widget description map



307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 307

def CreateAutoStartWidget(settings)
  settings = deep_copy(settings)

  start_auto_button = Ops.get_locale(
    settings,
    "start_auto_button",
    # radio button
    _("During Boot")
  )
  # radio button

  start_manual_button = Ops.get_locale(
    settings,
    "start_manual_button",
    _("Manually")
  )
  # radio button

  start_socket_button = Ops.get_locale(
    settings,
    "start_socket_button",
    _("Via &socket")
  )
  socket_available = Builtins.haskey(
    settings,
    "get_service_start_via_socket"
  )
  help = if Builtins.haskey(settings, "help")
    Ops.get_string(settings, "help", "")
  else
    socket_available ? AutoStartSocketHelp() : AutoStartHelp()
  end

  items = VBox(
    VSpacing(0.4),
    Left(
      RadioButton(Id("_cwm_startup_auto"), Opt(:notify), start_auto_button)
    )
  )
  if socket_available
    items = Builtins.add(
      items,
      Left(
        RadioButton(
          Id("_cwm_startup_socket"),
          Opt(:notify),
          start_socket_button
        )
      )
    )
  end
  items = Builtins.add(
    items,
    Left(
      RadioButton(
        Id("_cwm_startup_manual"),
        Opt(:notify),
        start_manual_button
      )
    )
  )
  items = Builtins.add(items, VSpacing(0.4))
  # Frame label (service starting)
  booting = VBox(
    # frame
    Frame(
      _("Service Start"),
      Left(RadioButtonGroup(Id("_cwm_service_startup"), items))
    )
  )

  if !(Builtins.haskey(settings, "set_service_auto_start") &&
      Builtins.haskey(settings, "get_service_auto_start"))
    booting = VBox()
    help = ""
  end

  ret = Convert.convert(
    Builtins.union(
      settings,

      "widget"        => :custom,
      "custom_widget" => booting,
      "help"          => help,
      "init"          => fun_ref(
        method(:AutoStartInitWrapper),
        "void (string)"
      ),
      "store"         => fun_ref(
        method(:AutoStartStoreWrapper),
        "void (string, map)"
      )

    ),
    from: "map",
    to:   "map <string, any>"
  )

  deep_copy(ret)
end

#CreateLdapWidget(settings) ⇒ Hash

Get the widget description map of the LDAP enablement widget TODO: Find a file to move to <pre>

LDAP support:

  • “get_use_ldap” : boolean () – function to return current status

    of the LDAP support. If not set, LDAP check-box is not shown.
    
  • “set_use_ldap” : void (boolean) – function to set the LDAP usage

    and report errors in case of fails. Status will be rechecked
    via "get_use_ldap". If not set, LDAP check-box is not shown.
    
  • “use_ldap_checkbox” : string – label of the chcek box to set if LDAP

    support is active.
    
  • “help” : string – help to the widget. If not specified, generic help

    is used (button labels are patched correctly)
    

</pre>

Parameters:

  • settings (Hash{String => Object})

    a map of all parameters needed to create the widget properly

Returns:

  • (Hash)

    the widget description map



762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 762

def CreateLdapWidget(settings)
  settings = deep_copy(settings)

  use_ldap_checkbox = Ops.get_locale(
    settings,
    "use_ldap_checkbox",
    # check box
    _("&LDAP Support Active")
  )
  help = if Builtins.haskey(settings, "help")
    Ops.get_string(settings, "help", "")
  else
    EnableLdapHelp()
  end

  # check box
  ldap_settings = VBox(
    VSpacing(1),
    Left(CheckBox(Id("_cwm_use_ldap"), Opt(:notify), use_ldap_checkbox))
  )

  if !(Builtins.haskey(settings, "get_use_ldap") &&
      Builtins.haskey(settings, "set_use_ldap"))
    ldap_settings = VBox()
    help = ""
  end

  ret = Convert.convert(
    Builtins.union(
      settings,

      "widget"        => :custom,
      "custom_widget" => ldap_settings,
      "help"          => help,
      "init"          => fun_ref(
        method(:LdapInitWrapper),
        "void (string)"
      ),
      "handle"        => fun_ref(
        method(:LdapHandleWrapper),
        "symbol (string, map)"
      ),
      "handle_events" => ["_cwm_use_ldap"]

    ),
    from: "map",
    to:   "map <string, any>"
  )

  deep_copy(ret)
end

#CreateStartStopWidget(settings) ⇒ Hash

Get the widget description map for immediate service start/stop and appropriate actions <pre>

  • “service_id” : string – service identifier for Service

    functions.

    If not specified, immediate actions buttons are not displayed.
    
  • “save_now_action” : void () – function that causes saving of all settings

    and restarting the service. If key is missing, the button
    is not displayed
    
  • “start_now_action” : void () – function that causes starting the service

    If not specified, generic function using "service_id" is used
    instead
    
  • “stop_now_action” : void () – function that causes stopping the service

    If not specified, generic function using "service_id" is used
    instead
    
  • “service_running_label” : string – label to be displayed if the service

    is running.
    
  • “service_not_running_label” : string – label to be displayed if the

    service is stopped.
    
  • “start_now_button” : string – label for the push button for immediate

    service start
    
  • “stop_now_button” : string – label for the push button for immediate

    service stop
    
  • “save_now_button” : string – label for the push button for immediate

    settings saving and service restarting
    
  • “help” : string – help to the widget. If not specified, generic help

    is used (button labels are patched correctly)
    

</pre>

Parameters:

  • settings (Hash{String => Object})

    a map of all parameters needed to create the widget properly

Returns:

  • (Hash)

    the widget description map



568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 568

def CreateStartStopWidget(settings)
  settings = deep_copy(settings)

  start_now_button = Ops.get_locale(
    settings,
    "start_now_button",
    # push button for immediate service starting
    _("&Start the Service Now")
  )
  # push button for immediate service stopping

  stop_now_button = Ops.get_locale(
    settings,
    "stop_now_button",
    _("S&top the Service Now")
  )

  save_now_button = Ops.get_locale(
    settings,
    "save_now_button",
    # push button for immediate saving of the settings and service starting
    _("S&ave Changes and Restart Service Now")
  )
  display_save_now = Builtins.haskey(settings, "save_now_action")

  help = if Builtins.haskey(settings, "help")
    Ops.get_string(settings, "help", "")
  else
    StartStopHelp(display_save_now)
  end

  save_now_button_term = if display_save_now
    PushButton(
      Id("_cwm_save_settings_now"),
      Opt(:hstretch),
      save_now_button
    )
  else
    VBox()
  end

  immediate_actions = VBox(
    # Frame label (stoping starting service)
    Frame(
      _("Switch On and Off"),
      Left(
        HSquash(
          VBox(
            HBox(
              # Current status
              Label(_("Current Status: ")),
              ReplacePoint(Id("_cwm_service_status_rp"), Label("")),
              HStretch()
            ),
            PushButton(
              Id("_cwm_start_service_now"),
              Opt(:hstretch),
              start_now_button
            ),
            PushButton(
              Id("_cwm_stop_service_now"),
              Opt(:hstretch),
              stop_now_button
            ),
            save_now_button_term
          )
        )
      )
    )
  )

  if !Builtins.haskey(settings, "service_id")
    immediate_actions = VBox()
    help = ""
  end

  ret = Convert.convert(
    Builtins.union(
      settings,

      "widget"        => :custom,
      "custom_widget" => immediate_actions,
      "help"          => help,
      "init"          => fun_ref(
        method(:StartStopInitWrapper),
        "void (string)"
      ),
      "handle"        => fun_ref(
        method(:StartStopHandleWrapper),
        "symbol (string, map)"
      ),
      "handle_events" => [
        :timeout,
        "_cwm_start_service_now",
        "_cwm_stop_service_now",
        "_cwm_save_settings_now"
      ]

    ),
    from: "map",
    to:   "map <string, any>"
  )

  if Builtins.haskey(settings, "service_id")
    Ops.set(ret, "ui_timeout", 5000)
  end
  deep_copy(ret)
end

#EnableLdapHelpString

Get the help text to the LDAP enablement widget

Returns:



737
738
739
740
741
742
743
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 737

def EnableLdapHelp
  Builtins.sformat(
    EnableLdapHelpTemplate(),
    # part of help text - check box label, NO SHORTCUT!!!
    _("LDAP Support Active")
  )
end

#EnableLdapHelpTemplateString

Get the template for the help text to the LDAP enablement widget

Returns:

  • (String)

    help text template with %1 and %2 placeholders



725
726
727
728
729
730
731
732
733
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 725

def EnableLdapHelpTemplate
  # help text for LDAP enablement widget
  # %1 is button label, eg. "LDAP Support Active" (without quotes)
  _(
    "<p><b><big>LDAP Support</big></b><br>\n" \
      "To store the settings in LDAP instead of native configuration files,\n" \
      "set <b>%1</b>.</p>"
  )
end

#HandleLdap(widget, event_id) ⇒ Object

Handle the “Use LDAP” check box param event_id any the ID of the occurred event

Parameters:

  • widget (Hash{String => Object})

    a map describing the widget



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 103

def HandleLdap(widget, event_id)
  widget = deep_copy(widget)
  event_id = deep_copy(event_id)
  if event_id == "_cwm_use_ldap"
    set_use_ldap = Convert.convert(
      Ops.get(widget, "set_use_ldap"),
      from: "any",
      to:   "void (boolean)"
    )
    use_ldap = Convert.to_boolean(
      UI.QueryWidget(Id("_cwm_use_ldap"), :Value)
    )
    set_use_ldap.call(use_ldap)
    UpdateLdapWidget(widget)
  end

  nil
end

#LdapHandle(widget, _key, event) ⇒ Symbol

Handle function of the widget

Parameters:

  • widget (Hash{String => Object})

    a widget description map

  • key (String)

    strnig the widget key

  • event (Hash)

    map event to be handled

Returns:

  • (Symbol)

    for wizard sequencer or nil



694
695
696
697
698
699
700
701
702
703
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 694

def LdapHandle(widget, _key, event)
  widget = deep_copy(widget)
  event = deep_copy(event)
  ret = Ops.get(event, "ID")
  if ret == "_cwm_use_ldap"
    HandleLdap(widget, ret)
    return nil
  end
  nil
end

#LdapHandleWrapper(key, event) ⇒ Symbol

Handle function of the widget

Parameters:

  • map

    widget a widget description map

  • key (String)

    strnig the widget key

  • event (Hash)

    map event to be handled

Returns:

  • (Symbol)

    for wizard sequencer or nil



718
719
720
721
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 718

def LdapHandleWrapper(key, event)
  event = deep_copy(event)
  LdapHandle(CWM.GetProcessedWidget, key, event)
end

#LdapInit(widget, _key) ⇒ Object

Init function of the widget

Parameters:

  • widget (Hash{String => Object})

    a widget description map

  • key (String)

    strnig the widget key



682
683
684
685
686
687
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 682

def LdapInit(widget, _key)
  widget = deep_copy(widget)
  UpdateLdapWidget(widget)

  nil
end

#LdapInitWrapper(key) ⇒ Object

Init function of the widget

Parameters:

  • key (String)

    strnig the widget key



707
708
709
710
711
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 707

def LdapInitWrapper(key)
  LdapInit(CWM.GetProcessedWidget, key)

  nil
end

#mainObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 35

def main
  Yast.import "UI"
  textdomain "base"

  Yast.import "CWM"
  Yast.import "Mode"
  Yast.import "ProductFeatures"
  Yast.import "Service"

  # private variables

  # Label saying that service is running
  @service_is_running = ""

  # Label saying that service is stopped
  @service_is_stopped = ""

  # Last status of the service
  @last_status = nil
end

#StartStopHandle(widget, _key, event) ⇒ Object

Handle the immediate start and stop of the service

Parameters:

  • widget (Hash{String => Object})

    a map describing the widget

  • key (String)

    strnig the widget key

  • event_id

    any the ID of the occurred event

Returns:

  • always nil



415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 415

def StartStopHandle(widget, _key, event)
  widget = deep_copy(widget)
  event = deep_copy(event)
  event_id = Ops.get(event, "ID")
  if event_id == "_cwm_start_service_now"
    if Builtins.haskey(widget, "start_now_action")
      start_now_func = Convert.convert(
        Ops.get(widget, "start_now_action"),
        from: "any",
        to:   "void ()"
      )
      start_now_func.call
    else
      Service.Restart(Ops.get_string(widget, "service_id", ""))
    end
    Builtins.sleep(500)
  elsif event_id == "_cwm_stop_service_now"
    if Builtins.haskey(widget, "stop_now_action")
      stop_now_func = Convert.convert(
        Ops.get(widget, "stop_now_action"),
        from: "any",
        to:   "void ()"
      )
      stop_now_func.call
    else
      Service.Stop(Ops.get_string(widget, "service_id", ""))
    end
    Builtins.sleep(500)
  elsif event_id == "_cwm_save_settings_now"
    func = Convert.convert(
      Ops.get(widget, "save_now_action"),
      from: "any",
      to:   "void ()"
    )
    func.call
    Builtins.sleep(500)
  end
  UpdateServiceStatusWidget(widget)
  nil
end

#StartStopHandleWrapper(key, event) ⇒ Object

Handle the immediate start and stop of the service

Parameters:

  • key (String)

    strnig the widget key

  • event_id

    any the ID of the occurred event

Returns:

  • always nil



481
482
483
484
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 481

def StartStopHandleWrapper(key, event)
  event = deep_copy(event)
  StartStopHandle(CWM.GetProcessedWidget, key, event)
end

#StartStopHelp(restart_displayed) ⇒ String

Get the help text to the start/stop widget

Parameters:

  • restart_displayed (Boolean)

    shold be true if “Save and restart” is displayed

Returns:



526
527
528
529
530
531
532
533
534
535
536
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 526

def StartStopHelp(restart_displayed)
  Builtins.sformat(
    StartStopHelpTemplate(restart_displayed),
    # part of help text - push button label, NO SHORTCUT!!!
    _("Start the Service Now"),
    # part of help text - push button label, NO SHORTCUT!!!
    _("Stop the Service Now"),
    # part of help text - push button label, NO SHORTCUT!!!
    _("Save Changes and Restart Service Now")
  )
end

#StartStopHelpTemplate(restart_displayed) ⇒ String

Get the template for the help text to the start/stop widget

Parameters:

  • restart_displayed (Boolean)

    shold be true if “Save and restart” is displayed

Returns:

  • (String)

    help text template with %1 and %2 placeholders



497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 497

def StartStopHelpTemplate(restart_displayed)
  # help text for service status displaying and switching  widget 1/2
  # %1 and %2 are push button labels
  # %1 is eg. "Start the Service Now"
  # %2 is eg. "Stop the Service Now"
  # (both without quotes)
  help = _(
    "<p><b><big>Switch On or Off</big></b><br>\n" \
      "To start or stop the service immediately, use \n" \
      "<b>%1</b> or <b>%2</b>.</p>"
  )
  if restart_displayed
    # help text for service start widget 2/2, optional
    # %3 is push button label, eg. "Save Changes and Restart Service Now"
    # (without quotes)
    # note: %3 is correct, do not replace with %1!!!
    help = Ops.add(
      help,
      _(
        "<p>To save all changes and restart the\nservice immediately, use <b>%3</b>.</p>\n"
      )
    )
  end
  help
end

#StartStopInit(widget, _key) ⇒ Object

Init function of the widget

Parameters:

  • widget (Hash{String => Object})

    a widget description map

  • key (String)

    strnig the widget key



459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 459

def StartStopInit(widget, _key)
  widget = deep_copy(widget)
  @last_status = nil
  @service_is_running =
    # service status - label
    Ops.get_locale(widget, "service_running_label", _("Service is running"))
  @service_is_stopped =
    # service status - label
    Ops.get_locale(
      widget,
      "service_not_running_label",
      _("Service is not running")
    )
  UpdateServiceStatusWidget(widget)

  nil
end

#StartStopInitWrapper(key) ⇒ Object

Init function of the widget

Parameters:

  • key (String)

    strnig the widget key



488
489
490
491
492
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 488

def StartStopInitWrapper(key)
  StartStopInit(CWM.GetProcessedWidget, key)

  nil
end

#UpdateLdapWidget(widget) ⇒ Object

Update the widget displaying if LDAP support is active

Parameters:

  • widget (Hash{String => Object})

    a map describing the widget



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 86

def UpdateLdapWidget(widget)
  widget = deep_copy(widget)
  return if !UI.WidgetExists(Id("_cwm_use_ldap"))
  get_use_ldap = Convert.convert(
    Ops.get(widget, "get_use_ldap"),
    from: "any",
    to:   "boolean ()"
  )
  use_ldap = get_use_ldap.call
  UI.ChangeWidget(Id("_cwm_use_ldap"), :Value, use_ldap)

  nil
end

#UpdateServiceStatusWidget(widget) ⇒ Object

Update the displayed status of the service

Parameters:

  • widget (Hash{String => Object})

    a map describing the widget



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 60

def UpdateServiceStatusWidget(widget)
  widget = deep_copy(widget)
  return if !UI.WidgetExists(Id("_cwm_service_status_rp"))
  if Mode.config
    UI.ChangeWidget(Id("_cwm_start_service_now"), :Enabled, false)
    UI.ChangeWidget(Id("_cwm_stop_service_now"), :Enabled, false)
    # service status - label
    UI.ReplaceWidget(Id("_cwm_service_status_rp"), Label(_("Unavailable")))
  else
    status = 0 == Service.Status(Ops.get_string(widget, "service_id", ""))
    if status != @last_status
      UI.ChangeWidget(Id("_cwm_start_service_now"), :Enabled, !status)
      UI.ChangeWidget(Id("_cwm_stop_service_now"), :Enabled, status)
      UI.ReplaceWidget(
        Id("_cwm_service_status_rp"),
        Label(status ? @service_is_running : @service_is_stopped)
      )
      @last_status = status
    end
  end

  nil
end