Class: Yast::CWMServiceStartClass Deprecated

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

Overview

Deprecated.

Use CWM::ServiceWidget instead.

Routines for service start widget handling.

Instance Method Summary collapse

Instance Method Details

#AutoStartHelpString

Get the help text to the auto start widget

Returns:


248
249
250
251
252
253
254
255
256
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 248

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


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

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


216
217
218
219
220
221
222
223
224
225
226
227
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 216

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


126
127
128
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
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 126

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


198
199
200
201
202
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 198

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

  nil
end

#AutoStartSocketHelpString

Get the help text to the auto start widget

Returns:


260
261
262
263
264
265
266
267
268
269
270
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 260

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


165
166
167
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
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 165

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


207
208
209
210
211
212
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 207

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

NOTE: a modern API for this is UI::ServiceStatus



- "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

Additional settings:

  • "help" : string -- help to the whole widget. If not specified, generic help is used (button labels are patched correctly)

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
# 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



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)

Parameters:

  • settings (Hash{String => Object})

    a map of all parameters needed to create the widget properly

Returns:

  • (Hash)

    the widget description map


756
757
758
759
760
761
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
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 756

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



- "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)

Parameters:

  • settings (Hash{String => Object})

    a map of all parameters needed to create the widget properly

Returns:

  • (Hash)

    the widget description map


566
567
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
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 566

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>"
  )

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

#EnableLdapHelpString

Get the help text to the LDAP enablement widget

Returns:


731
732
733
734
735
736
737
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 731

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


719
720
721
722
723
724
725
726
727
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 719

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


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

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


688
689
690
691
692
693
694
695
696
697
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 688

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


712
713
714
715
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 712

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


676
677
678
679
680
681
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 676

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


701
702
703
704
705
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 701

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

  nil
end

#mainObject


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 30

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


413
414
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
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 413

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


479
480
481
482
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 479

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:


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

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


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

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


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

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


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

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


82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 82

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


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'library/cwm/src/modules/CWMServiceStart.rb', line 55

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